This is the source $pData
array I have:
Array
(
[code] => 105132
[globalImages] => Array
(
[0] => 1148-1578-image_41ddeeef69eb94a8d9ccc1503d099810.jpg
)
[envImages] => Array
(
[0] => 1148-0-image_72e95c6424ec7bcd90994f1c0a3f4544.jpg
)
[attribs] => Array
(
[0] => Array
(
[0] => Array
(
[id] => 1578
[uniqCode] => 105132-1578
[parentId] => 0
[type] => Colour
)
)
)
)
When I call a value using the following (line 337
):
<?php echo strtolower($pData['attribs'][0][0]['type']);?>
PHP Error log has the following line:
[13-Jan-2010 11:48:21] PHP Notice: Undefined offset: 0 in D:\apps\path\to\file\pages\product.php on line 337
What could I be doing wrong? As far as I see, there is nothing wrong with this simple call. May be someone see something fishy?
Thanks for any input!
EDIT 01:
I forgot to say that the echo
produces correct result. But it also makes the specified entry entry in the error log.
The var_dump($pData['attribs'])
output:
array(1) {
[0]=>array(2) {
[0]=>array(22) {
["id"]=>string(4) "1578"
["uniqCode"]=>string(11) "105132-1578"
["parentId"]=>string(1) "0"
["type"]=>string(6) "Colour"
["title"]=>string(5) "Beech"
["swatch"]=>string(22) "variant-437-swatch.jpg"
["width"]=>string(4) "1830"
["depth"]=>string(3) "610"
["height"]=>string(3) "740"
["floorToSeat"]=>string(1) "0"
["unit"]=>string(2) "mm"
["weight"]=>float(89)
开发者_StackOverflow社区 ["volume"]=>float(2.311)
["groupPack"]=>int(1)
["fobkl"]=>string(3) "407"
["br3"]=>string(3) "441"
["br2"]=>string(3) "467"
["br1"]=>string(3) "496"
["rcp"]=>string(3) "515"
["gwm"]=>string(3) "592"
["gem"]=>string(3) "618"
["images"]=>array(1) {
[0]=>string(52) "1148-1578-image_41ddeeef69eb94a8d9ccc1503d099810.jpg"
}
}
[1]=>array(22) {
["id"]=>string(4) "1577"
["uniqCode"]=>string(11) "105132-1577"
["parentId"]=>string(1) "0"
["type"]=>string(6) "Colour"
["title"]=>string(13) "Natural Maple"
["swatch"]=>string(22) "variant-436-swatch.jpg"
["width"]=>string(4) "1830"
["depth"]=>string(3) "610"
["height"]=>string(3) "740"
["floorToSeat"]=>string(1) "0"
["unit"]=>string(2) "mm"
["weight"]=>float(155.06)
["volume"]=>float(20.305)
["groupPack"]=>int(1)
["fobkl"]=>string(3) "407"
["br3"]=>string(3) "441"
["br2"]=>string(3) "467"
["br1"]=>string(3) "496"
["rcp"]=>string(3) "515"
["gwm"]=>string(3) "592"
["gem"]=>string(3) "618"
["images"]=>array(1) {
[0]=>string(52) "1148-1577-image_9c4fc8337e5c106ea6b69863e68f54bb.jpg"
}
}
}
}
A debugger can help to find the error, e.g. xdebug and netbeans as frontend.
Please verify that the source line in question really is echo strtolower($pData['attribs'][0][0]['type'])
, e.g. by using an error handler like:
function myErrorHandler($errno, $errstr, $errfile, $errline, $errcontext)
{
if ( E_NOTICE===$errno && is_readable($errfile) ) {
$source = file($errfile);
for($i=max(0,$errline-4); $i<$errline+3; $i++ ) {
if ( isset($source[$i]) ) {
if ( $i+1===$errline ) {
echo ' >>> ';
}
echo $source[$i];
}
}
}
return false;
}
$old_error_handler = set_error_handler('myErrorHandler');
I can't see anything wrong - the only possibility is that you defined one or both of the 0 keys as a string '0', making it an associative index (rather than numeric)
$pData['attribs']['0']['0']['type'] = 'Colour';
In which case you'd also need to refer to it as a string
Do your print_r on the row just before the echo, so you are sure that you see the array that your function actually work on. It could be a scoping problem (i.e., $pData is a local array in a function and you call echo outside that function).
精彩评论