Note that there are some explanatory texts on larger screens.

plurals
  1. POArray losing a key on the way
    primarykey
    data
    text
    <p>Hello i have a piece of code with an example of array and the problem is that i'm loosing a key of the array. The array is a multidimensional one and i have posted here an sample version because i have a lot of keys in it ( too long to post it ) </p> <pre><code>$columns = array( "1" =&gt; array( "foo" =&gt; "bar", "bar" =&gt; "foo", "foo" =&gt; "bar", "bar" =&gt; "foo", "foo" =&gt; "bar", "bar" =&gt; "foo", "foo" =&gt; "bar", "bar" =&gt; "foo", "foo" =&gt; "bar", "bar" =&gt; "foo", ); $array = array( "1" =&gt; array( "foo" =&gt; "bar", "bar" =&gt; "foo", "foo" =&gt; "bar", "bar" =&gt; "foo", "foo" =&gt; "bar", "bar" =&gt; "foo", "foo" =&gt; "bar", "bar" =&gt; "foo", "foo" =&gt; "bar", "bar" =&gt; "foo", ), "2" =&gt; array( "1" =&gt; "bar", "2" =&gt; "foo", "3" =&gt; "bar", "4" =&gt; "foo", "5" =&gt; "bar", "6" =&gt; "foo", "7" =&gt; "bar", "8" =&gt; "foo", "9" =&gt; "bar", "10" =&gt; "foo", ) ); </code></pre> <p>ok in this two arrays i have a fixed number or keys and what i want to achieve is getting the values from the first array and use them as keys in my second array. So far so good but when i do the second foreach to get the values from first and put them as keys in the second on the way i'm loosing on of my keys from $array ( i think it rewritten ). can you help me out with this code because i have no ideea how to fix it.</p> <pre><code>foreach($array as $key =&gt; $val) { array_splice($val, 66); foreach($val as $k =&gt; $row) { if ( isset($columns[$k])) { $info[$columns[$k]] = $row; } } return $info; } </code></pre> <p>Update:</p> <p>What i wanted to achieve here was creating an array using an array for keys and another one for values. Later on discovered that i can do it with array_combine. Solved my problem</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload