0

I am working on a project.In this i need to assign values in array with different location of code.first i used the $bd=array('1','420'); $bd=array('2','520'); etc.but when i echo $bd[1]; and echo $bd[2]; only last inserted value(520) is displayed.do you have any solution for it?

3
Contributors
3
Replies
5
Views
4 Years
Discussion Span
Last Post by daniel36
1

Hi,

You may want to try using array_push() function.

example of usage...

<?php
    $bd= array('1','420'); 

    array_push($bd,'2','520');

    echo $bd[0].'<br/>';
    echo $bd[2].'<br/>';
    echo $bd[1].'<br/>';
    echo $bd[3].'<br/>';
0

You way is not proper to achieve your aim.

Use any of the following 2 ways

Way 1

<?php
$bd=array('1'=>'420','2'=>'520'); 
echo $bd[1]."<br>"; 
echo $bd[2]; 

?>

Way 2

<?php
$bd[1]=420;
$bd[2]=520;

echo $bd[1]."<br>";  
echo $bd[2]; 

?>
0

now the array is working correctly but now i am having problem with sorting the array .i am usig $bsd2=sort($bsd); $bed2=sort($bed); to sort two array $bsd and $bed. and displaying via $bsd2[0]; bsd2[1] etc.but it is not working.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.