0

I am having an array like this

Array
(
    [0] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
            [3] => 4
            [4] => 6
            [5] => 7
            [6] => 8
            [7] => 9
        )

    [4] => Array
        (
            [0] => 2
            [1] => 3
            [2] => 4
            [3] => 5
            [4] => 6
            [5] => 7
            [6] => 8
            [7] => 9
            [8] => 10
            [9] => 11
        )

)

Now i want to put this into another array using array_push keyword... How can i achieve this?

1
  • 1
    What you mean with another? This array and combine arrays? Create new array and appand all values to one? Be clear in your question, especially when you talk about another where you already have 3 arrays in you example code! Commented Apr 28, 2014 at 9:12

2 Answers 2

1
<?php
    foreach($yourArray as $array) {
        array_push($firstArray, $array);
    }
?>

or

<?php
    foreach($yourArray as $array) {
       $firstArray[] = $array;
    }
?>

or

<?php
    array_push($firstArray, $array);
?>
Sign up to request clarification or add additional context in comments.

2 Comments

Then write $array[0] ? Or specify your question. This are all possible things you can perform - to put one array or one array element into another.
If you just wanna remove one element from the array(here the 0th element, checkout >unset()<
0
 $shiftedarray=array();
    $aftershift=array();
    foreach($twodarray as $key=>$val)
    {
        //Remove 0th index in array
        $shiftedarray[]=array_shift($val);
        //Array After Removed 0th index
        $aftershift[]=$val;

    }
    echo "<pre>";
    print_r($shiftedarray);
    print_r($aftershift);
   $oneDimensionalArray = call_user_func_array('array_merge', $aftershift);

print_r($oneDimensionalArray);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.