Re: Problem with array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Not sure if it works for numeric indices, but maybe you could replace
$piece[3] with (array_key_exists(3, $piece) ?  $piece[3] : ""). If you
want you could abstract that into a function, like

function array_access_element($key, $srch_array, $def=""){
return array_key_exists($key, $srch_array) ? $srch_array[$key] : $def;
}


On 6/17/05, Ross <ross@xxxxxxxxxxxxx> wrote:
> As with my previous post the problem is the pieces of the array can vary
> from 1 to 4 items. So pieces 3 and 4 are often undefined giving the
> 'undefined index' notice. All I really want to do is display the array
> pieces if they EXIST. But as they are inside a echo statement so I can't
> even to a for loop...can I?
> 
> 
> Any ideas?
> 
> R.
> 
> 
> if ($quantity == 0){
> 
>     }
>    else {
> 
>  $pieces = explode(" ", $quantity);
> 
> 
>    $formatted_price = sprintf('%0.2f', $pricecode);
>   echo "<table width=\"240\" border=\"0\" cellpadding=\"2\"
> cellspacing=\"5\"><tr><td valign=\"top\" align=\"right\"
> width=\"40\">$pieces[0]</td><td align=\"left\" width=\"60\"></td><td
> align=\"left\" width=\"200\">$pieces[1]  $pieces[2] $pieces[3]
> $pieces[4]</td><td valign=\"top\" align=\"left\"
> width=\"80\">$formatted_price</td></tr></table>";
> 
> 
> 
> 
> 
>    }
>    }
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux