php/arrayz

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
User avatar
xlordt
New php-forum User
New php-forum User
Posts: 34
Joined: Thu Dec 12, 2002 9:00 pm
Location: NJ
Contact:

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
Computer/Programm rox.. (php, c/c++ will take over soon muhahah

User avatar
Joan Garnet
Moderator
Moderator
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars
Contact:

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
WiZARD
Moderator
Moderator
Posts: 1240
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

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."/");
        }
    }
}
}
"Sex,Drugs and Rock&Roll " replaced at "Sucks,Bugs and Plug&Play";
Image

Post Reply