thara Posted September 7, 2013 Share Posted September 7, 2013 I have a multidimensional array and it is like this - Array ( [Monday] => Array ( [open] => 05.00 PM [close] => 04.00 PM [state] => 0 ) [Tuesday] => Array ( [open] => [close] => [state] => 1 ) [Wednesday] => Array ( [open] => 03.00 AM [close] => 06.00 PM [state] => 0 ) [Thursday] => Array ( [open] => [close] => [state] => 1 ) [Friday] => Array ( [open] => 05.00 PM [close] => 03.00 PM [state] => 0 ) [Saturday] => Array ( [open] => 05.00 PM [close] => 06.00 PM [state] => 0 ) [Sunday] => Array ( [open] => [close] => [state] => 1 ) ) Using this array I want to make an output like this - Monday - 05.00 PM - 04.00 PM Tuesday - Closed Wednesday - 03.00 AM - 06.00 PM Thursday - Closed Friday - 05.00 PM - 03.00 PM Saturday - 05.00 PM - 06.00 PM Sunday - Closed I tried it with 2 foreach loop. But I couldn't get to work to expecting output. foreach ($result as $days => $values) { echo "$days"; foreach ($values as $k) { echo " - $k"; } echo "<br/>"; } Its ouptput is similar to this - Monday - 05.00 PM - 04.00 PM - 0 Tuesday - - - 1 Wednesday - 03.00 AM - 06.00 PM - 0 Thursday - - - 1 Friday - 05.00 PM - 03.00 PM - 0 Saturday - 05.00 PM - 06.00 PM - 0 Sunday - - - 1 Can anybody tell me how can I figure this out?NOTE: if `state = 0` it doesn't need to display and `state = 1` it should be `Closed`Any ideas would be greatly appreciated.Thank you. Link to comment https://forums.phpfreaks.com/topic/281955-display-multidiamentional-array-in-a-customize-way/ Share on other sites More sharing options...
vinny42 Posted September 7, 2013 Share Posted September 7, 2013 So, IF the state==1 THEN you want to echo "closed", ELSE you want to ECHO the open and close times... :-) Link to comment https://forums.phpfreaks.com/topic/281955-display-multidiamentional-array-in-a-customize-way/#findComment-1448603 Share on other sites More sharing options...
Andy-H Posted September 7, 2013 Share Posted September 7, 2013 echo '<pre>'; foreach($result as $day => $store_data) { if ( !empty($store_data['open']) ) { echo "{$day}\t - {$store_data['open']} - {$store_data['close']}"; } else { echo "{$day}\t - Closed"; } } Link to comment https://forums.phpfreaks.com/topic/281955-display-multidiamentional-array-in-a-customize-way/#findComment-1448604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.