PHP shift_array multi dimension

Hi All,

Just to check if anyone has an idea on how to do array_shift() function in php for multi dimension. For example:

$tmpArr[0][name] = 'myname'
$tmpArr[0][gender] = 'male'

In this situation if I use array_shift(), I would only get 'myname' instead of both value. Could somebody help me?
encusAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

shanikawmCommented:
Look at this simple example code. You may get a clear idea. This prints

Original Array
--------------

Array
(
    [0] => Array
        (
            [name] => myname
            [gender] => male
        )

    [1] => Array
        (
            [name] => friendname
            [gender] => female
        )

)

Shifted Part
---------------

Array
(
    [name] => myname
    [gender] => male
)

After Shifting
----------------

Array
(
    [0] => Array
        (
            [name] => friendname
            [gender] => female
        )

)

<?php
$tmpArr[0]['name'] = 'myname';
$tmpArr[0]['gender'] = 'male';
$tmpArr[1]['name'] = 'friendname';
$tmpArr[1]['gender'] = 'female';
 
echo "Original Array\n--------------\n\n";
 
print_r($tmpArr);
 
echo "\nShifted Part\n---------------\n\n";
 
print_r(array_shift($tmpArr));
 
echo "\nAfter Shifting\n----------------\n\n";
 
print_r($tmpArr);
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ddrudikCommented:

<pre>
<?php
$tmpArr[0]['name'] = 'myname0';
$tmpArr[0]['gender'] = 'male0';
$tmpArr[1]['name'] = 'myname1';
$tmpArr[1]['gender'] = 'male1';
echo '$tmpArr '.print_r($tmpArr,true);
echo 'first array_shift '.print_r(array_shift($tmpArr),true);
echo 'second array_shift '.print_r(array_shift($tmpArr),true);
?>
 
output:
$tmpArr Array
(
    [0] => Array
        (
            [name] => myname0
            [gender] => male0
        )
 
    [1] => Array
        (
            [name] => myname1
            [gender] => male1
        )
 
)
first array_shift Array
(
    [name] => myname0
    [gender] => male0
)
second array_shift Array
(
    [name] => myname1
    [gender] => male1
)

Open in new window

0
shanikawmCommented:
Refer following too.

http://www.php.net/array_shift
0
encusAuthor Commented:
Thanks all I have configure it. It was due to my while loop issue and now it works properly
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.