PHP array keys in a constant -
i have quick question. have placed array in constant when add array keys craps out. code below.
<?php define("my_const_arr", serialize(array("page_ids" => array("1234", "4123")))); ?> <?php $page_id = "4123"; ?> <?php if(in_array($page_id, unserialize(my_const_arr["page_ids"]))): ?> <h1>hello stackoverflow</h1> <?php endif; ?>
you can't my_const_arr["page_ids"] @ point because it's still string. should unserialize first , access
$arr = unserialize(my_const_arr); if(in_array($page_id, $arr["page_ids"])):
Comments
Post a Comment