Jump to content

Recommended Posts

using php, how to delete values from an array and place those values in another array.
Is it possible to take an array like this...
Array ( [0] => Array ( [0] => var1 [1] => 1 [2] => var2 [3] => 2 [4] => 3 ) )

and make two arrays like this...
Array ( [0] => Array ( [0] => 1 [1] => 2 [2] => 3 ) )
Array ( [0] => Array ( [0] => var1 [1] => var2 ) )

The word "var" inside of the array does not change value but numbers can change values.

If var1 and var2 never change then you can pre-construct that array then create the third array from the difference

$arr = array (
            array('var1', 1, 'var2', 2, 3)
        );
$result[0] = array ('var1', 'var2');    //pre-construct

$result[1] = array_values(array_diff($arr[0], $result[0]));

echo '<pre>',print_r($result, true),'</pre>';

gives

Array
(
    [0] => Array
        (
            [0] => var1
            [1] => var2
        )

    [1] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )

)
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.