Filter through an array of Objects in PHP -
i have array of objects when being pulled in database , return each object 'status' field equal 'no answer':
array (size=21) 0 => object(customer)[4] public 'id' => string '12345' (length=6) public 'date' => string '2014-02-16' (length=10) public 'first_name' => string 'jane' (length=5) public 'last_name' => string 'doe' (length=4) public 'email' => string 'test@test.com' (length=21) public 'phone' => string '01782111444' (length=11) public 'status' => string 'no answer' (length=14) 1 => object(customer)[5] public 'id' => string '12346' (length=6) public 'date' => string '2014-02-19' (length=10) public 'first_name' => string 'john' (length=4) public 'last_name' => string 'smith' (length=9) public 'email' => string 'no@no.com' (length=24) public 'phone' => string '01606555666' (length=11) public 'status' => string 'left message' (length=12) it seems need use array_filter() cant seem work
like @wiseguy commented, should doing in query, not code.
see array_filter():
array_filter($array, function($i) { if(strtolower($i->status) == 'no answer') { return true; } else { return false; } });
Comments
Post a Comment