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

  • SEARCH
  • Home
  • 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 7436929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:19:04+00:00 2026-05-29T10:19:04+00:00

So if having a multidimensional array like: Got it from here (as a demo):

  • 0

So if having a multidimensional array like:

Got it from here (as a demo): PHP. Loop through an array and get items with attributes in common

$data

Array
(
    [0] => stdClass Object
        (
            [term_id] => 3
            [name] => Comercial
        )

    [1] => stdClass Object
        (
            [term_id] => 4
            [name] => Escolar
        )

    [2] => stdClass Object
        (
            [term_id] => 5
            [name] => Kinder
        )

    [3] => stdClass Object
        (
            [term_id] => 6
            [name] => Primaria
        )

    [4] => stdClass Object
        (
            [term_id] => 7
            [name] => Secundaria
        )

    [5] => stdClass Object
        (
            [term_id] => 1
            [name] => Uncategorized
        )

)

Having 0,1,2,3,4,5 stdClass Objects, how can I create individual arrays for each std Object dynamically.

By that I mean that the function should be able to create $varX array, where X is the array number of the stdObject, automatically…

$var0 = $data[0];
$var1 = $data[1];
and so on, determined by $data first level count of arrays.


Edit:
I got carried away and forgot to mention the most important question:

Having $var0, $var1… is very important because for a later use of all or each one individually.

So

  • Needs to create X variables according to the count of first level of the multidimensional array
  • each $varX needs to be accessible in common with the rest of $varX or individually.

    $count = count($data); //6

    foreach ($data as $key => $value)
    {
    $var.$key = $value;
    }

Ok, that function works partially because from there I don’t know how to make it automatically add $val1,$val2… to (ex:) array_intersect($val1,$val2,$val3...

  • 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-29T10:19:05+00:00Added an answer on May 29, 2026 at 10:19 am

    The easiest way would be to use extract.

    extract($data, EXTR_PREFIX_ALL, 'var');
    

    With that said, it will add an underscore (_) after the prefix (e.g. var_0).

    Update:

    Regarding your edit, you could simply call array_intersect using call_user_func_array. There’s no need for variables.

    call_user_func_array('array_intersect', $data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php multidimensional array which looks like this: $fields = array( array('input',
let's say I have a really complicated multidimensional array like this: Array ( [A]
I have a multidimensional array that looks like this: Array ( [0] => Array
I have a multidimensional array. The contents look like this in the debugger. The
I have an single-dimensional array of PHP objects. Each object has two attributes, one
I'm having trouble with multidimensional arrays in PHP. I'm assuming this should be simple
I am having a hard time trying recursively sort a multidimensional array on its
I'm having issues with returning a multidimensional array. I create the array in a
I've got a multidimensional array of which I can't know the depth. The array
I would like to build a function that takes a multidimensional array and prints

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.