Here is how I set my Array:
$Post_Cat_Array = array();
while($row = mysql_fetch_array( $result )) {
$Post_Cat_Array[$row['type_id']] = $row['type_name'];}
in this function I need to get the type_id(key) of a specific type_name(value)
function NameToID($input){
echo array_search($input, $Post_Cat_Array);
}
and I call the function like this :
NameToID($_POST['type']);
But it’s not working. It doesn’t echo anything. I am sure the $_POST['type'] contains correct value.
note:value of $_POST['type'] is in arabic. same with all values of the array.
It seems that
$Post_Cat_Arrayis out of scope. Modify your function:and then:
From PHP Variable scope: