3
In a list of books within a array
multidimensional, each sub_array
has a column category different, I would like to search in this array
by a category for example:
Array "livros"
(
[Livro 1] => Array
(
[titulo] => Bleach
[resumo] => xxx
[categoria] => Ação, Comédia...
)
[Livro 2] => Array
(
[titulo] => Titulo livro 2
[resumo] => xxx
[categoria] => Ação, Psicológico, Romance ...
)
[livro 3] => Array
(
[titulo] => Titulo do livro 3
[resumo] => xxx
[categoria] => Romance, Vampiros ...
)
)
I would like to research for example which books fit in the category "Romance", I did some research and found what might be the solution, but for some reason is not working, that would be this function:
$romances = array_keys(array_column($livros, 'categoria'), 'Romance');
The above function brings no value, only one array
empty, what I’m doing wrong?
The problem is that this function will already be executed, within another foreach, because I have an array with the categories and each time it goes to fetch all books in this category, it is not heavy one foreach within another?
– Leo Letto
It gives anyway, Leo. You could use a native function that you would give anyway because an iteration is also done on the array.
– Daniel Omine
There is nothing to do one way or another (natively or not) will have to happen
– Miguel
I think with
stripos()
could dispense with thestrtolower()
– Daniel Omine
I tested this @Danielomine, http://ideone.com/xmvJHL, can’t, is case sensitive
– Miguel
The
strpos()
is different fromstripos()
. Note that you have an "I" of "insensitive.– Daniel Omine
Ha is right, it’s true I forgot this @Danielomine, thanks I will edit
– Miguel
Personal vlw worked really well, I was breaking my head here with this kk
– Leo Letto
:) good thing you solved @Leoletto. You’re welcome
– Miguel