Illegal string offset Warning PHP
- Article
- Comment
Illegal string offset Warning PHP. Whenever you see this error. you will feel that its messed up our code. But its a simple mistake we did it on the array of parameter. Normally we have an array with key and its value as like the following one.
<?php $test_array = array( 'first_key' => 'first', 'second_key' => 'second', 'third_key' => 'third', 'four_key' => 'four' ); ?>
Here the above array has some values. But when you call this array with not set parameter it will throw an illegal offset parameter like the following one.
<?php if($test_array['fifth_key'] != 0 ){ //some code } ?>
for such a kind of issues, we can use this way.
<?php if(isset($test_array['fifth_key'])){ if($test_array['fifth_key'] != 0 ){ //some code } }
Here the ” isset ” function will help use to solve this error.