<?php
//define a array
$smilies = array(
':)' => 'smile.png',
'=)' => 'smile.png',
':|' => 'neutral.png',
'=|' => 'neutral.png',
':(' => 'sad.png',
'=(' => 'sad.png',
':D' => 'big_smile.png',
'=D' => 'big_smile.png',
':o' => 'yikes.png',
':O' => 'yikes.png',
';)' => 'wink.png',
':/' => 'hmm.png',
':P' => 'tongue.png',
':p' => 'tongue.png',
':lol:' => 'lol.png',
':mad:' => 'mad.png',
':rolleyes:' => 'roll.png',
':cool:' => 'cool.png');
//show each of the value and key
foreach ($smilies as $smiley_text => $smiley_img)
{
echo "key is $smiley_text value is $smiley_img <br />";
}
?>
其中数组来自某php的源码,这里将其简化,让大家明白如何使用这样的东西
<?php
//define a array
$smilies = array(
':)' => 'smile.png',
'=)' => 'smile.png',
':|' => 'neutral.png'
);
//show each of the value and key
foreach ($smilies as $smiley_text => $smiley_img)
{
echo "key is $smiley_text value is $smiley_img <br />";
}
$nCount = count($smilies);
echo "the count of array is $nCount <br />";
echo array_pop($smilies).'<br />';
echo "the count of array is $nCount <br />";
// if we use array_pop ,then the array is delete the
// end of the value ,so that we can't find the value
echo 'bad We can\'t find value of :| '.$smilies[':|'].'<br />';
echo 'good find it '.$smilies[':)'].'<bar />';
?>
在来看一些操作。。大家可以自己运行一下!
这里给出显示.
key is :) value is smile.png
key is =) value is smile.png
key is :| value is neutral.png
the count of array is 3
neutral.png
the count of array is 3
Notice: Undefined index: :| in C:\PHPnow-1.5.6\htdocs\arry.php on line 19
bad We can't find value of :|
good find it smile.png