N
N
Nikolay Erofeev2016-10-18 14:26:56
PHP
Nikolay Erofeev, 2016-10-18 14:26:56

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();

But $people->user_setting_services can store not only ["1"], it's categories, all categories that it enters are stored
["1","2","4" и т.д.]
How to look for a value in this array and continue to select further from the database?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2016-10-18
@webinar

'["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 question

Ask a Question

731 491 924 answers to any question