Help with for loop or looping till match with array

I have an array which has the data of books and uids. The array changes and does not have a set amount of data. Now i want to compare the uid of each array to a uid in my database and if matched then print out the book name. I thought For each may work but had no luck. here is a sample of my array with print_r function.

Array
(
[data] => Array
(
[0] => Array
(
[book] => fairy
[uid] => 11 )

        [1] => Array
            (
                [book] => Kloet
                [uid] => 46                )

I had tryed the following but had no luck.

<?php
$x= $bookarray;
foreach ($x as $value)
{
//check that uid matchs
$query =“SELECT uid FROM books WHERE uid='”.$x.“'”;
$result = mysql_query($query);
$affected_rows = mysql_num_rows($result);
//If match found.
if ($affected_rows==1)
{
echo $value . “<br />”;
}
}
?>

thank you for any help

First thing’s first - you’re stating in your foreach “$x as $value”, so you’ll need to use $value not $x inside the loop to access that data.

Secondly, if your data is an array inside an array, you’ll need to be calling the array that includes your data (i.e. $x[‘data’] not $x) (that may not have made as much sense as I hoped it would - let me know if you’d like it explained further).

oh i get it now,
$x= $bookarray[‘data’];
and
$value[‘uid’]
worked a treat thanks.