Regarding Arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
harishprasadp
Forum Newbie
Posts: 2
Joined: Sun Apr 26, 2009 6:14 am

Regarding Arrays

Post by harishprasadp »

Hi,

i'm pretty new to php and i was working with arrays, while i came into this strange result
below is my code
<html>
<head>
<title> Arrays Functions</title>
</head>
<body>
<?php $array1 = array(16,23,56,78,43,67,27); ?>
Count: <?php echo count($array1); ?><br />
Max: <?php echo max($array1); ?><br />
Min: <?php echo min($array1); ?><br />
Sort: <?php echo sort($array1); print_r($array1); ?><br />
Reverse Sort: <?php echo rsort($array1); print_r($array1); ?>
Implode: <?php echo $string1=implode(" * ", $array1); ?><br />
Explode: <?php echo print_r(explode(" * ", $string1))?>
In Array: <?php echo in_array(77,$array1); ?>
</body>
</html>
while i run this code i get this result
Count: 7
Max: 78
Min: 16
Sort: 1Array ( [0] => 16 [1] => 23 [2] => 27 [3] => 43 [4] => 56 [5] => 67 [6] => 78 )
Reverse Sort: 1Array ( [0] => 78 [1] => 67 [2] => 56 [3] => 43 [4] => 27 [5] => 23 [6] => 16 ) Implode: 78 * 67 * 56 * 43 * 27 * 23 * 16
Explode: Array ( [0] => 78 [1] => 67 [2] => 56 [3] => 43 [4] => 27 [5] => 23 [6] => 16 ) 1 In Array:
my issues is before Every Array there is a numeric one which is being displayed i have highlighted in red color, could some one kindly letme know why it is appearing???

Sorry if this question is stupid

Thank you all in advance
Harish
Yossarian
Forum Contributor
Posts: 101
Joined: Fri Jun 30, 2006 4:43 am

Re: Regarding Arrays

Post by Yossarian »

Code: Select all

echo sort($array1)
Manaul for sort()
sort();

Return Values

Returns TRUE on success or FALSE on failure.
Returns 1, true, it did the sort.

You don't need the echo, you are using print_r(),

Use print_r or var_dump() to recursively go through an array.
harishprasadp
Forum Newbie
Posts: 2
Joined: Sun Apr 26, 2009 6:14 am

Re: Regarding Arrays

Post by harishprasadp »

Thank you bro :D, You resolved my issue...
Post Reply