Notice: Undefined index although element defined in array

I am getting strange error on one my application server .
Its working on other servers but failing only on one particular server .
Following is the code :slight_smile:

<?php
ini_set("display_errors", "1");
error_reporting(E_ALL);
$mov_arr = array();
$mov_arr = array("specification_id_1"=>"test","specification_id1"=>"test","specification_id"=>22);
echo "<pre>";
print_r($mov_arr);


echo $mov_arr['specification_id'];
echo $mov_arr['specification_id1'];
echo $mov_arr['specification_id_1'];


//$specification_id=21;
echo $mov_arr['specification_id'];

in output it shows :
Array
(
[specification_id_1] => test
[specification_id1] => test
[specification_id] => 22
)

Notice: Undefined index: specification_id in /var/www/production/dataentry_pincodewise/CatetoryCreationRequestModule/jira_3070/movie_test2.php on line 11
testtest
Notice: Undefined index: specification_id in /var/www/production/dataentry_pincodewise/CatetoryCreationRequestModule/jira_3070/movie_test2.php on line 17

its only showing this message for : specification_id .
rest of the elements its printing fine .
Unable to understand the reason .
PHP version :PHP Version 7.0.2
its working fine on other server with same version .

This problem usually occurs when you have a non-printing, white-space, or encoded character as part of the index name. You can add - var_dump(array_keys($mov_arr)); to help diagnose the problem. I would delete and retype the entire index name, including the enclosing quotes, in the array assignment statement.

Sponsor our Newsletter | Privacy Policy | Terms of Service