Find in array smarty

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.

-------------Problems Reply------------

You need to loop over while array.

{foreach from=$data key='k' item='i'}
{if $i.cnt == 1180}
{assign var='key' value=$k}

Value 1180 is in key {$key}.


If smarty has something like break, you can add it into if condition.

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}

You can simply use array_column function of PHP as

$arr = array(

print_r(array_column($arr, 'cnt'));

Category:php Views:10 Time:2018-12-12
Tags: php arrays smarty

Related post

  • How to find the array length in unix shell? 2009-12-11

    How to find the array length in unix shell? --------------Solutions------------- $$ a=(1 2 3 4) $$ echo ${#a[@]} 4 Assuming bash: ~> declare -a foo ~> foo[0]="foo" ~> foo[1]="bar" ~> foo[2]="baz" ~> echo ${#foo[*]} 3 So, ${#ARRAY[*]} e

  • What is the fastest way to find an array within another array in Java? 2010-03-01

    Is there any equivalent of String.indexOf() for arrays? If not, is there any faster way to find an array within another other than a linear search? --------------Solutions------------- Regardless of the elements of your arrays, I believe this is not

  • How to find an array from parent array 2010-06-04

    I am using below code to find an array inside parent array but it is not working that is retuning empty even though the specified key exits in the parent array $cards_parent = $feedData['BetradarLivescoreData']['Sport']['Category']['Tournament']['Mat

  • Programming Pearls: finding sub-array with max sum 2010-09-21

    I was reading "programming pearls" book and stuck in some place. The (best) original solution for the problem (finding sub-array with max sum) is: maxsofar = О maxendinghere = О for i = [0. n) { maxendinghere = max(maxendinghere + x[i], 0) maxsofar =

  • Find an array inside another larger array 2010-10-15

    I was recently asked to write 3 test programs for a job. They would be written using just core Java API's and any test framework of my choice. Unit tests should be implemented where appropriate. Although I haven't received any feedback at all, I supp

  • Jasmin Assembler VerifyError : Expecting to find object/array on stack 2011-07-15

    i get this error after "java testphase": C:\jasmin-2.4>java testphase Exception in thread "main" java.lang.VerifyError: (class: testphase, method: main signature: ([Ljava/lang/String;)V) Expecting to find object/array on stack Could not find the m

  • Find an array for hasMany relationship 2011-07-19

    I have relations like this: Project has multiple Properties Property has multiple Rates On the project page, I want to display: The project, its properties and its latest rate So far, I have this: $this->set('rates', $this->Rate->find('all',

  • Find inner arrays in nested arrays 2011-11-19

    I have a nested array in PHP: array ( '0' => "+5x", '1' => array ( '0' => "+", '1' => "(", '2' => "+3", '3' => array ( '0' => "+", '1' => "(", '2' => array ( // I want to find this one. '0' => "+", '1' => "(", '2' =

  • Mongodb - Find Embedded Array in PHP 2012-02-01

    I have a collection called Forms: Inside that collection i have a sub collect called Form_Fields. So a document may look like this: } "_id": ObjectId("4f2984b1af06e80418000000"), "Form_Name": "Users", "Form_Fields": [ {"Field_Name": "First_Name"}, {"

  • Given a sequence a[1], a[2], -, a[n], find an array b[1] < b[2] < - < b[n] such that |a[1]-b[1]| + |a[2]-b[2]| + - + |a[n]-b[n]| is minimum 2015-01-26

    I've recently stumbled upon the following problem: Given a sequence a[1], a[2], ..., a[n], find an array b[1] < b[2] < ... < b[n] such that |a[1]-b[1]| + |a[2]-b[2]| + ... + |a[n]-b[n]| is minimum. I have already come up with some observatio

  • Finding an array element by id returned by Active Record collection in rails 2009-11-11

    I am trying to synchronize members in the db with an external source My plan was to use the array collection in the active record class and on each update for a member found in the external source, I would remove that member entry in the array(if it

  • Finding Duplicate Array Elements 2010-02-02

    I've been struggling to create a function to essentially find all the indices of duplicate elements in a multi-dimensional array(unsorted), in this case a 5x5 array, and then using the indices found changing the parallel elements in a score array. Bu

  • Trying to find if array is full or not 2010-02-10

    I'm working with JQuery to determine if an array, built earlier, with a determined number of indexes, is full or not. When created, array looks like this : ,,,,,, All I want to do is find if every position is filled or not. So bascially, i'm trying t

  • Finding sub-array matches in PHP 2010-03-09

    I have an array in the format: array ( '1' => array ( 'id' => '2', 'qty' => '4' ), '2' => array ( 'id' => '1', 'qty' => '1' ), '3' => array ( 'id' => '2', 'qty' => '3' ), '4' => array ( 'id' => '4', 'qty' => '6' )

  • Finding an array of ids while keeping the order with Rails and PostGreSQL 2010-10-26

    I have an array of ids of objects that I want to get from the database, but PostGreSQL returns them sorted by ids: Users.find([4, 1, 3]) => [User 1, User 3, User 4] I know I could sort them back like this: ids = [4, 3, 1] r = Users.find(ids) users

  • what is the way to find if array contain Arithmetic progression (sequence) 2010-11-02

    i have sorted array of numbers like 1, 4, 5 , 6, 8 what is the way to find out if this array contain Arithmetic progression (sequence) ? like in this example 4,6,8 or 4,5,6 remark : the minimum numbers in sequence is 3 --------------Solutions--------

  • Finding which array contributes the maximum value for classification 2010-11-08

    Given 2 2x2 Numpy arrays, each element having a value between 0 and 1, I would like to find the one array of the 2 that has the maximum value, and do that comparison element-wise. For example, given: A = [[.6 .2] [.3 .4]] and B = [[.4 .5] [.7 .1]], I

  • Find the array interval with most values present in the array 2011-01-21

    Example Sorted Position vector [4, 5, 9, 30, 31, 32, 34, 40, 47] Interval length = 6 I would like to find the maximum number of values in any given interval of length 6. In the above mentioned example, the intervals will be [Array value - Array value

  • Find an array (byte[]) inside another array? 2011-02-01

    What is the simplest way to find a byte[] inside another byte[]? i have a feeling i could do it with linq but i dont know how. Note: I did a search with the [c#] and didnt find anything, i am surprised. --------------Solutions------------- Here's a s

  • javascript find in array 2011-02-04

    I have an array like this: var movies = [ { Name: "The Red Violin", ReleaseYear: "1998", Director: "François Girard" }, { Name: "Eyes Wide Shut", ReleaseYear: "1999", Director: "Stanley Kubrick" }, { Name: "The Inheritance", ReleaseYear: "1976", Dire

  • Getting an attribute directly from rails Class.find(:all) array of objects 2011-02-14

    I know that Person.find(:all) returns an array of Person objects but is there somehow I can just get 'name' property of all people in the Person table? Something like Person.find(:all).names --------------Solutions------------- Use :select to retriev

  • Finding FORTRAN array location, 4-dimensional array 2011-04-27

    Hey guys, I have a question. If given a four dimensional array in FORTRAN, and told to find a location of a certain part of it (with a starting location of 200 and 4 bytes per integer). Is there a formula to find the location if is stored in row-majo

  • find all array elements in another array 2011-07-22

    I have two arrays- $ar = array("a","b","c"); $xy = array("a","b","c","d","e"); I have to find out each element in $ar in $xy. If all elements are in $xy then it should return true. I used in_array() but it returns true though one element is found. An

  • find character array length in Android 2011-09-05

    to get length of string String str=strLenData.toString(); int ipLen= str.length(); return ipLen; whatever be the value of strLenData, value of str= [[email protected] As a result, for every char[] I input, the length is shown as 11. I have to use the lengt

  • How to find character array length in Android 2011-09-06

    I had used the following code to find the length String str=strLenData.toString(); int ipLen= str.length(); return ipLen; ipLen would return 11 every time. whatever be the actual value of strLenData. when I call toString() function, value of str: "[C

Copyright (C), All Rights Reserved.

processed in 0.210 (s). 11 q(s)