Search code examples
undefinedoffset

Undefined offset notice messages


Hello I'm facing undefined offset notice messages. I have exploded the array and then I'm fetching the array element 5. Please guide me to fix this issue.

Notice: Undefined offset: 5

function test() {       
$path_val=request_path();    
$exploded_val=explode("/",$path_val);    
if(isset($exploded_val)){
$entity_id=$exploded_val[5];
}}

Solution

  • try this

    if(!empty($exploded_val[5])){//doAction}