Nice to meet you!
In the following array of the items table associated with the Favorites table (Item hasMany Favorite),
I would like to search the user_id of Favorite to see if there is a 10 in the user_id, but I don't know what to do.
What code should I write in this case?
If you know anything, please take good care of me.
<?phpecho$item['Favorite'][0]['user_id'];?>
displays 12.
$dataForView=array(
'items' = > array(
(int) 0 = > array(
'Item' = > array(
maximum depth reached
),
'Purchase' = > array(
maximum depth reached
),
'Favorite' = > array(
user_id=>12
)
),
(int) 1 = > array(
'Item' = > array(
maximum depth reached
),
'Purchase' = > array(
maximum depth reached
),
'Favorite' = > array(
user_id=>23
)
),
//(int)2 to continue
For Cake2 and later, it is convenient to use the Hash utility class.
$found=Hash::extract($dataForView, 'items.{n}.Favorite [user_id=10]');
This extracts all favorite favorites whose user_id
matches 10.
If you can't find it, the empty array will return, so you can make a decision.
© 2024 OneMinuteCode. All rights reserved.