php - putting the array data into separate variables
I am trying to put the array data into two separate variables. But not getting it. Here is my code
if($option_query->row['type'] == 'date') {
$array1[0] = $option_value;
foreach ($array1 as $key => $value) {
echo "$key = $value<br>";
}
Now i am getting the result :
0 = 2013-05-05
0 = 2013-05-07
I want to put 1st date in a variable calleddatestart
and 2nd date in todateend
.
How can I achieve this?
output for var_dump(array1);
array (size=1)
0 => string '2013-05-05' (length=10)
array (size=2)
0 => string '2013-05-05' (length=10)
1 => string '2013-05-07' (length=10)
EDITED HERE (ADDING)
if($option_query->row['type'] == 'date' )
{
$arr = array( //Assuming that this should be the map of your array
array(
$option_value
),
array(
$option_value
//$option_value
)
);
// var_dump($arr);
echo $arr[1][0];
echo $arr[1][1];
}
}
I echoed like this and got the o/p
2013-05-20
2013-05-30
It works!!!!!
Answer
Solution:
There's no need to loop, if you've an array like
Update : Your array is a nested array, you need to use this
Answer
Solution:
If you're sure $array1 has two rows and that ones are the dates you need, you may look at the list builtin function :
Answer
Solution:
Are the dates in
$array1
sorted ascending? If not you should callasort($array)
to sort it low-to-high.Answer
Solution: