Answer the question
In order to leave comments, you need to log in
How to find values in an array that lies with a parent array?
Hello. There is an array which is stored in a db. I need to find all the records that are equal to 1.
I enter it into the database using serialize, then I make a selection, and I put the entries into a new array, but I bring the values in a normal form using unserialize. Array view
$peoples = user_settings::all();
$Ids = [];
foreach($peoples as $people){
if(unserialize($people->user_setting_services) == '["1"]'){
$Ids[] = $people->user_setting_user_id;
}
}
$peoples = User::whereIn('id',$Ids)->orderBy('user_likeds','desk')->get();
["1","2","4" и т.д.]
Answer the question
In order to leave comments, you need to log in
'["1"]' is strange, it probably means:
$myarray = unserialize($people->user_setting_services);
if(in_array('1',$myarray)){
echo "ok";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question