Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

php/arrayz

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

php/arrayz

Postby xlordt » Tue Jan 21, 2003 9:12 am

welp im up to the part were i get to learn arrrays in php.. and its almost the same as in c .. but yet.. i dont get it (ya its true i know some c but arrays is diffrent in someways) can anyone please explain to me by showing me an example of arrays on how to deal with them..
for example can you show me using some linux commands like..
ls , cat, pwd, etc.. im tring to understand how arrays work on php... thanx
User avatar
xlordt
New php-forum User
New php-forum User
 
Posts: 34
Joined: Thu Dec 12, 2002 9:00 pm
Location: NJ

Postby Joan Garnet » Tue Jan 21, 2003 2:38 pm

Code: Select all
/////////////////////////////////////////////////////////////
//simple array///////////////////////////////////////////////
/////////////////////////////////////////////////////////////
$simple_array = array('one','two','three');
echo "<pre>";//to view the shape with a better format
print_r ($simple_array);//will output this simple array
echo "</pre><br>";
/////////////////////////////////////////////////////////////
//a bidimensional array//////////////////////////////////////
/////////////////////////////////////////////////////////////
$my_array = array(   'colors' => 'red',
               'fruits' => 'apple',
               'hair'   => 'curly'
               );
echo "<pre>";
print_r ($my_array);
echo "</pre><p>";
/////////////////////////////////////////////////////////////
//let's get some values//////////////////////////////////////
/////////////////////////////////////////////////////////////
echo $my_array["colors"]."<br>";
echo $my_array["fruits"]."<br>";
echo $my_array["hair"]."<p>";

Anyway...
http://www.phpfreaks.com/phpmanual/page ... array.html
This a complete explanation
;)
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars

Re: php/arrayz

Postby WiZARD » Wed Jan 22, 2003 8:55 am

From manual ls:
Code: Select all
function GetDirArray($sPath)
{
//Load Directory Into Array
$handle=opendir($sPath);
while ($file = readdir($handle))
{
        $retVal[count($retVal)] = $file;
}
//Clean up and sort
closedir($handle);
sort($retVal);
//return $retVal;

while (list($key, $val) = each($retVal))
{
if ($val != "." && $val != "..")
{
        $path = str_replace("//","/",$sPath.$val);
        echo "$path
";
        if (is_dir($sPath.$val))
        {
        GetDirArray($sPath.$val."/");
        }
    }
}
}
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 4 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.