I have an called $array as follows. I need to be able to pull out specific arrays within it based off the [day] value.
So for instance, I could have $day2 equal to $array[1] because its day value is 2 and so on. How can I go about doing that? They are not ordered when they come in and there cannot be multiples as in the max amount of arrays in $array can be 7 as there are 7 days in the week.
Array
(
[0] => Array
(
[time_id] => 1
[user_id] => 4
[day] => 1
[12a] => 0
[1a] => 0
[2a] => 0
[3a] => 0
[4a] => 0
[5a] => 0
[6a] => 0
[7a] => 0
[8a] => 0
[9a] => 0
[10a] => 0
[11a] => 0
[12p] => 1
[1p] => 1
[2p] => 1
[3p] => 1
[4p] => 1
[5p] => 1
[6p] => 1
[7p] => 1
[8p] => 0
[9p] => 0
[10p] => 0
[11p] => 0
)
[1] => Array
(
[time_id] => 2
[user_id] => 4
[day] => 2
[12a] => 1
[1a] => 1
[2a] => 1
[3a] => 1
[4a] => 1
[5a] => 1
[6a] => 1
[7a] => 1
[8a] => 1
[9a] => 1
[10a] => 1
[11a] => 1
[12p] => 1
[1p] => 1
[2p] => 1
[3p] => 1
[4p] => 1
[5p] => 1
[6p] => 1
[7p] => 1
[8p] => 1
[9p] => 0
[10p] => 1
[11p] => 1
)
)
EDIT for anyone interested :
Here is what I ended up with... $settings being the original multi array...
//set counter
$counter = 0;
//loop through and set different day arrays
foreach($settings as $value) {
// inc counter
$counter++;
//set array using variable variables ($hourstemp is actually $hours1, $hours2, $hours3, etc.)
if($value['day'] == $counter) {
$hourstemp = 'hours'.$counter;
$$hourstemp = $value;
}
}
$array[1]to a new variable called$day2because$array[1]['day'] == 2? So you want to have 7 new variables,$day1,$day2,$day3,$day4,$day5,$day6,$day7All matching on the $array[X]['day']?