Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7063235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:41:23+00:00 2026-05-28T04:41:23+00:00

I have two arrays containing different keys and values. However, some keys store strings

  • 0

I have two arrays containing different keys and values. However, some keys store strings (integers) which I want to mix together in a single array (ie array_merge). All I need is to achieve is to collect these integers.

using var_dump the arrays look like these:

this is the first one

array
    0 => 
        array
           'featured_pic' => string '740' (length=3)
    1 => 
        array
           'featured_pic' => string '741' (length=3)
    2 => 
        array
          'featured_pic' => string '742' (length=3)

and this is the second one

array
   0 => 
     array
       'accommodation_roomphoto' => string '456' (length=3)
       'accommodation_roomname' => string 'Single room' (length=11)
       'accommodation_roomsize' => string 'single' (length=6)
       'price_unit' => string '60' (length=2)
       'price_currency' => string 'USD' (length=3)
   1 => 
     array
       'accommodation_roomphoto' => string '434' (length=3)
       'accommodation_roomname' => string 'Double room' (length=11)
       'accommodation_roomsize' => string 'double' (length=6)
       'price_unit' => string '80' (length=2)
       'price_currency' => string 'USD' (length=3)

what I really need is featured_pic from array#1 and accommodation_roomphoto from array#2. I need to collect all those numbers into a single array (I don’t need the keys anymore – all I need is a series of numbers that come from those keys, in the example above: 740, 741, 742, 456, 434):

array
   0 => '740'
   1 => '741'
   2 => '742'
   3 => '456'
   4 => '434'

the resulting array should be something like the example above (order is not important)

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:41:24+00:00Added an answer on May 28, 2026 at 4:41 am

    If you know the keys you are interested in, this is just a simple looping job:

    $result = array();
    
    foreach ($array1 as $item) {
      if (isset($item['featured_pic'])) $result[] = (int) $item['featured_pic'];
    }
    foreach ($array2 as $item) {
      if (isset($item['accommodation_roomphoto'])) $result[] = (int) $item['accommodation_roomphoto'];
    }
    
    print_r($result);
    

    Alternatively if you don’t know the keys you want, this routine will grab all numbers stored as strings from both arrays:

    $result = array();
    
    foreach ($array1 as $item) {
      foreach ($item as $sub) {
        if (is_numeric($sub)) $result[] = (int) $sub;
      }
    }
    foreach ($array2 as $item) {
      foreach ($item as $sub) {
        if (is_numeric($sub)) $result[] = (int) $sub;
      }
    }
    
    print_r($result);
    

    …however this will not give you result you want from the array above, because the price_unit key in the second set of arrays is also numeric.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two arrays containing the same elements, but in different orders, and I
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have two arrays with time values in them in this format. 00:00:00 which
I have two arrays, each containing strings. The first array is a list of
supposing to have two arrays a[N],b[N] containing only 0 and 1 values, is there
I have a function which takes two arrays containing the tokens/words of two texts
Hi I have a text file containing two arrays and one value(all integers) like
Hi I have two arrays containing 4 columns and I want to subtract the
I have two arrays of values like X,Y,Z and 1,2 There is a table
I have a javascript array containing the name and values of radios I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.