Reply to Re: Swapping array elements from two different arrays

Your name:

Reply:


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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация