I have a array with values based on a specific player and I want to use some of these values(match_id and minutes) to compare to a second array and then create the third array to hold the returned values.
I'm writing this for a Joomla based website and so I'm using an inbuilt array funtions LoadRowList(); which returns an indexed array of indexed arrays from the table records returned by the query.
The first array contains values populated based on a particular player
$search = array();
$query = "SELECT first_name,match_id,m_name,minutes,points
FROM #__bl_players as pl,#__bl_match_events as me,#__bl_matchday as md, #__bl_match as m
WHERE pl.id = me.player_id
AND pl.id = ".$player_id."
AND me.match_id = m.id
AND m.m_id = md.id
";
$db->setQuery($query);
$search = $db->loadRowList();
The $search array outputs an array in the format below. print_r($search);
Array (
[0] => Array ( [0] => Marco [1] => 33 [2] => Xornada 04 [3] => 7 [4] => 3 )
[1] => Array ( [0] => Marco [1] => 129 [2] => Xornada 08 [3] => 1 [4] => 2 )
[2] => Array ( [0] => Marco [1] => 129 [2] => Xornada 08 [3] => 6 [4] => 2 )
)
The second array contains hundreds of records with the same layout as the first.
$data = array();
$query = "SELECT first_name,match_id, m_name,minutes,ecount
FROM #__bl_players as pl,#__bl_match_events as me,#__bl_matchday as md, #__bl_match as m
WHERE pl.id = me.player_id
AND me.match_id = m.id
AND m.m_id = md.id
AND md.s_id = ".$s_id."
";
$db->setQuery($query);
$data = $db->loadRowList();
The $data array outputs in the same format as above. print_r($data);
Array (
[0] => Array ( [0] => Pablo [1] => 8 [2] => Xornada 01 [3] => 2 [4] => 3 )
[1] => Array ( [0] => Juan Ramón [1] => 9 [2] => Xornada 01 [3] => 1 [4] => 0 )
[2] => Array ( [0] => Pedro [1] => 9 [2] => Xornada 01 [3] => 1 [4] => 3 )
)etc etc etc
And finally, I need the third array to be populated by records that are a match between the $search and $data arrays based only on match_id and minutes.
Array(
[0]=>Array ([1]=> PlayerName(from the first array)[2]=> MatchID[3]=> MatchName[4]=> TimePlayed[5]=> Score(from the first array)[6]=> Score(from the second array)[7]=> PlayerName(from the second array))
)etc etc etc
I have revised my original question to include more information I'm no expert so I'm looking for all and any ideas and feedback. Thanks
Note:The column names areas follows Name = first_name, Match ID = match_id, Match name = m_name,The event time = minutes and the Points scored = points
Issues I'm having In response to comments this is my problem take the following code for example (its only an example):
$matches = array();
foreach ($data as $entry){
if ($entry[2] == $search[2]) {
match =$search;
$matches[] = $match
}
}
print_r($mtaches)
If I use a comparison like $entry[2] == $search[2] it will be comparing the 2nd arrays from each ie
`[2] => Array ( [0] => Marco [1] => 129 [2] => Xornada 08 [3] => 6 [4] => 2 )
==
[2] => Array ( [0] => Pedro [1] => 9 [2] => Xornada 01 [3] => 1 [4] => 3 )`
so my question is how do you use a type of wildcard so I can compare key values ie
$entry[*][2] == $search[*][2]
Thanks to everyone for their help and patience and especially to @erisco for sharing his knowledge
array_walk()
or similar to write your own function - php.net/manual/en/function.array-walk.php – jakenoble Feb 1 '11 at 10:35