Array not working

Hi all, I am trying to build a “Rack builder” for military ribbons.
When I run this code all works as expected except the array($my_Ribbons) it always comes back as 1/0.

Any help? Thanks

$my_Ribbons = array ();
for ($X = 1; $X <= 32; $X += 1){

if($row_rsRibbons['Ribbion'.$X]!="0") {
echo "<img src='images/ribbions/".$X.".png' />";
echo $row_rsRibbons['Ribbion'.$X];
$my_Ribbons[$X] = $B; <-- Trying to Append/Add $B into the array
echo $B;<-- This echos out 1,2,3,...9 Correct

function DivideIT($B){
echo "<BR />B=".$B."<BR />";<-- This echos out correct 9
$C = $B/4;
echo "<p>C=".$C;//<-- This echos out correct 1.25
echo "<p> my_Ribbons ".sizeof($my_Ribbons);<-- this echos out 1/0. Should be whatever $B is

What do you mean by 1/0? Sizeof() should return 0 in your case.

The problem is - you have defined array $my_Ribbons outside of function DivideIT(), so you either need to declare it as global parameter, or pass array via function argument.

Example 1:
[php]function DivideIT($B,$my_Ribbons){
// …

Example 2:
[php]function DivideIT($B){
global $my_Ribbons;
// …

Now I know I need to set it as global first.


the 1/0 line was when I was tesing. Now it was late and I had been staring at the screen for a long time so anything could have poped up on my screen :-[

Sponsor our Newsletter | Privacy Policy | Terms of Service