Reputation: 109
I have an array
Array
(
[0] => Array
(
[id] => 32
[type] => 4
)
[1] => Array
(
[id] => 51
[type] => 9
)
..
..
..
..
..
[84] => Array
(
[id] => 51
[type] => 9
[cnt] => 1180
)
)
And i need to find value of [cnt] in my array, which lies only in one index of my entire array. The index of [cnt] is not constant.
Upvotes: 1
Views: 4072
Reputation: 21422
You can simply use array_column
function of PHP as
$arr = array(
array('id'=>1,'value'=>'asdas'),
array('id'=>1,'value'=>'asdas'),
array('id'=>1,'value'=>'asdas'),
array('id'=>1,'value'=>'asdas'),
array('id'=>1,'value'=>'asdas','cnt'=>1185)
);
print_r(array_column($arr, 'cnt'));
Upvotes: 1
Reputation: 27072
You need to loop over while array.
{foreach from=$data key='k' item='i'}
{if $i.cnt == 1180}
{assign var='key' value=$k}
{/if}
{/foreach}
Value 1180 is in key {$key}
.
{$data[$key]|print_r}
If smarty has something like break
, you can add it into if
condition.
EDIT:
If you need to find value of cnt
, it should be:
{foreach from=$data key='k' item='i'}
{if isset($i.cnt)}
CNT value is: {$i.cnt}
Key of item with CNT: {$k}
{/if}
{/foreach}
Upvotes: 2