Jump to content

Display Multidiamentional array in a customize way.


thara

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.