简体   繁体   中英

how to display more than one array

I have got a problem with my script, I'm still trying to find out how to display more than one array, I can only display no more than one array.

Here is the output:

20140426100000

Here is the PHP:

<?php
$array = array(
    "10:00 AM",
    "11:00 AM",
    "12:00 PM",
    "12:30 PM",
    "2:00 PM",
    "2:30 PM",
    "9:00 PM",
    "11:00 PM",
    "12:00 AM",
    "12:30 AM",
    "1:00 AM",
    "1:30 AM",
    "2:00 AM",
    "11:00 PM",
    "12:00 AM",
    "12:30 AM",
    "1:00 AM",
);

// Save the output format
$DATE_FORMAT_STRING = "YmdHis";

// function to get the state
function getState($string){
    $ex = explode(" ",$string);
    return $ex[1];
}

// GET the current STAGE
$current_state = getState($array[0]);
$offset = 0;

foreach($array as $time){

    // Get the item state.  
    $this_state = getState($time);

    // check if we past a day? 
    if($current_state == "PM" && $this_state == "AM"){
        $offset++;
    }
$this_unix = strtotime($time) + (60 * 60 * 24 * $offset);
echo date($DATE_FORMAT_STRING, $this_unix);
    echo "<br></br";

    $current_state = $this_state;
}
?>

Can you please tell me how to display more than one array which it would display like this?

20140426100000
20140426110000
20140426120000
20140426123000
20140426140000
20140426143000
20140426210000
20140426230000
20140427000000
20140427003000
20140427010000
20140427013000
20140427020000
20140427110000
20140427120000
20140427123000
20140427130000

Your code works fine. Your error is an HTML one. You're missing the closing bracket on one of your <br> tags. This causes you to not see the output on your page.

echo "<br></br"; <-- HERE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM