Created
February 9, 2015 15:25
-
-
Save vimes1984/a0cb02c4a52985280b8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** Default values used later **/ | |
//Sample items array | |
$items = array( | |
'item_one' => "value one",//simple string | |
'number' => 3,//Number | |
'multidimension' => array( | |
"sub_item_one" => "subvalue_one", | |
"sub_item_two" => "subvalue_two" | |
),//Multidimensional | |
); | |
//Empty array since php doesn't like assigning new array items on the fly | |
$arrayName = array(); | |
//A simple counter this will keep track of what number we are at in the foreach so we can do things with EACH item being iterated over | |
$i = 0; | |
//Our foreach will do an action for each item in items! in this case it will move it through to our new array | |
foreach ($items as $key => $value) { | |
# code... | |
$arrayName[$i]['EXAMPLEONE'] = $value['item_one']; | |
$arrayName[$i]['exampletwo'] = $value['multidimension']; | |
$arrayName[$i]['examplethree'] = $value['number']; | |
//Increase $i byu one so we can then move the array to the next item | |
$i++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment