Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Question

Post Timeline

Commonmark migration
Source Link

The easiest way for me to explain this is to show an example ... Here's a replication of the problem code:

<?php
 $test=array();
 $test['one']='hello';
 if(isset($test['one']['two'][0])) {
 echo 'Apparently it is set ...';
 echo $test['one']['two'][0];
 }
?>

This returns as:

Apparently it is set ...

Warning: Illegal string offset 'two' in C:\test.php on line 6

h

Is this because there are mixed key types? It's just a little anomaly I came across and was wondering if someone could shed some light on it ...

The easiest way for me to explain this is to show an example ... Here's a replication of the problem code:

<?php
 $test=array();
 $test['one']='hello';
 if(isset($test['one']['two'][0])) {
 echo 'Apparently it is set ...';
 echo $test['one']['two'][0];
 }
?>

This returns as:

Apparently it is set ...

Warning: Illegal string offset 'two' in C:\test.php on line 6

h

Is this because there are mixed key types? It's just a little anomaly I came across and was wondering if someone could shed some light on it ...

The easiest way for me to explain this is to show an example ... Here's a replication of the problem code:

<?php
 $test=array();
 $test['one']='hello';
 if(isset($test['one']['two'][0])) {
 echo 'Apparently it is set ...';
 echo $test['one']['two'][0];
 }
?>

This returns as:

Apparently it is set ...

Warning: Illegal string offset 'two' in C:\test.php on line 6

h

Is this because there are mixed key types? It's just a little anomaly I came across and was wondering if someone could shed some light on it ...

Source Link
Just Lucky Really
  • 1.4k
  • 2
  • 19
  • 38

Php array offset passes 'isset', even though it's not set

The easiest way for me to explain this is to show an example ... Here's a replication of the problem code:

<?php
 $test=array();
 $test['one']='hello';
 if(isset($test['one']['two'][0])) {
 echo 'Apparently it is set ...';
 echo $test['one']['two'][0];
 }
?>

This returns as:

Apparently it is set ...

Warning: Illegal string offset 'two' in C:\test.php on line 6

h

Is this because there are mixed key types? It's just a little anomaly I came across and was wondering if someone could shed some light on it ...

lang-php

AltStyle によって変換されたページ (->オリジナル) /