Arrays - Problem accessing the single element
| From: | Trystano at aol dot com | Date: | Wed, 30 Apr 2003 13:17:25 +0000 |
| Subject: | Arrays - Problem accessing the single element | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-19734@lists.php.net to get a copy of this message | ||
Hi, all, i'm having problems accessing the one data element that is contained
within my array I have created. Its quite a strange problem and have included
a sample of the area of the script that is causeing me problems. Please could
you try to identify where I may be going wrong.
<Code>
// Create an array of the appointment times
$AppTimes = array( "10:00:00", "10:30:00", "11:00:00",
"11:30:00",
"12:00:00", "12:30:00", "13:00:00", "13:30:00",
"14:00:00", "14:30:00",
"15:00:00" );
// create an array to store the occupied times in.
$occupied = array($occupiedAppNum);
for ($j=0; $j < $occupiedAppNum; $j++)
{
$occupiedApp = mysql_fetch_array( $occupiedAppResult );
$occupiedDate = (stripslashes ($occupiedApp[ "time" ]));
$occupied[$j] = $occupiedDate;
}
In the for loop above I have created another array and then populated the
array with all the times of a given day that have been scheduled for an
appointment. I now have two arrays, $AppTimes, and $occupied.
// Create a new array that contains all the free time slots
$diff = array_diff($AppTimes, $occupied);
sort( $diff );
$diffAmount = sizeof( $diff );
then I create a separate array containing the free appointment slots. In the
code I am testing at the moment I should have one data element (time slot)
within the array.
If I run the following code, I can print the data out
foreach ( $diff as $val ) {
print "$val<br>";
}
But if I try to print out the data element with the following line of code, I
don't get anything output.
Print $diff[0];
If there is only one data element in the array then it should be at position
'0', and this should print out its value, shouldn't it??
Thanks in advance for anyone who can help me.
Tryst