Fatal error: Cannot use [] for reading in

Hello i am new here also new in php

i have problem with my code
[php]
$seller_id = $listings[][‘Account_ID’];
$seller_info = $rlAccount -> getProfileInfo( $seller_id );
$rlSmarty -> assign_by_ref( ‘seller_info’, $seller_info );
[/php]

i get this error Fatal error: Cannot use [] for reading in

the array is
[php]
Array (
[0] => Array
(
[name] => Automobiles
[ID] => 1
[Account_ID] => 0
)
[1] => Array
(
[name] => Automobiles
[ID] => 2
[Account_ID] => 1
)
.
.
.
.
)
[/php]

Please help how i can fix it

When you use [], it’s only for adding an item to an array. If you want to use the last item in the array (and they’re all numeric keys from 0,1,2,3 etc etc), you could use the following:

[php] $seller_id = $listings[count($listings) - 1][‘Account_ID’];[/php]

We use the count function to get the number of items in the array, and then take away one (as arrays start with the index of 0) - to get the last item.

Sponsor our Newsletter | Privacy Policy | Terms of Service