|
Posted by Chris on 11/10/07 14:40
On 10 Nov, 11:18, "badar.wa...@gmail.com" <badar.wa...@gmail.com>
wrote:
> On Nov 10, 3:28 pm, Chris <matchett...@googlemail.com> wrote:
>
> > How would I replace the elements with matching keys between $array1
> > and $array2 to end up with 'a,b,c,d,e,f'.
>
> > $array1 - Array ( [2] => c [3] => d )
>
> > $array2 - Array ( [0] => a [1] => b [2] => x [3] => x [4] => e [5] =>
> > f )
>
> > Many thanks,
>
> > Chris
>
> you can use this code
>
> foreach($array1 as $key => $value)
> {
> if(array_key_exists($key, $array2))
> {
> $array2[$key] = $value;
> }
>
>
>
> }- Hide quoted text -
>
> - Show quoted text -
Cheers,
That has solved my problem...fuller snippet given below.
// Performing SQL query
dbConnect("$db");
$query = "SELECT * FROM room";
$result = mysql_query($query) or die("Query failed : " .
mysql_error());
$query_booking = "SELECT * FROM booking WHERE weeknumber =
$weeknumber";
$result_booking = mysql_query($query_booking) or die("Query failed :
" . mysql_error());
while($rowRoom = mysql_fetch_array($result, MYSQL_ASSOC)) {
$timetable = explode(',', $rowRoom['timetable']);
}
while($rowBooking = mysql_fetch_array($result_booking, MYSQL_ASSOC)) {
$period = $rowBooking['period'];
$teacher = $rowBooking['teacher'];
$booking[$period] = "$teacher";
}
foreach($timetable as $key => $value)
{
if(array_key_exists($key, $booking))
{
$int = $key -1;
$timetable[$int] = $booking[$period];
}
}
Chris
Navigation:
[Reply to this message]
|