"prices" => array ( if((date("H") < 10)) ( "7200" => "0.02",) "86400" => "0.95", "432000" => "2.22", "2592000" => "4.13" ), __________________________ It works without this part if((date("H") < 10)) ( "7200" => "0.02",) Am I doing something wrong? I basically want it to display the 0.02 price from 00:00 to 10:00
Do you mean similar like this? $prices = array( "86400" => "0.95", "432000" => "2.22", "2592000" => "4.13" ); if((date("H") < 10)) { $prices["7200"] = "0.02"; asort($prices); } Code (markup):
"prices" => array ( "7200" => "0.17", "18000" => "0.35", "86400" => "0.95", "432000" => "1.49", "2592000" => "2.99" ), Code (markup): This is what I have right now and it works. But when I try to do something like this: "prices" => array ( if((date("H") < 10)) ( "7200" => "0.02",) "7200" => "0.17", "18000" => "0.35", "86400" => "0.95", "432000" => "1.49", "2592000" => "2.99" ), Code (markup): It doesn't work. I just want to add the "7200" => "0.02", field when the time is < 10h.
You can't enter any code into an array definition. You can add your value after the definition. Check my previously post.
Ok thanks a lot. But how can I apply this without changing the array into the $prices = array(-style code that you mentioned?
Not easy, because I can't see the code, but I think you want to show smallest value before 10h. Your array is this: $stuff = array( "prices" => array( "7200" => "0.17", "18000" => "0.35", "86400" => "0.95", "432000" => "1.49", "2592000" => "2.99" ) ); Code (markup): For replace the value, just put this code after array: if((date("H") < 10)) { $stuff["prices"]["7200"] = "0.02"; } Code (markup): You can check finally like this: print_r($stuff); Code (markup):