Jump to content

array question


Tandem

Recommended Posts

Quick question about arrays that i'm sure i've done lots of times but can't test it right now.

If i have an array full or values, and then i set the array to false, would it empty the entire array?

For example:
[code]
$blah[0] = 1;
$blah[1] = 9;
$blah[2] = 4;
$blah[3] = 45;

$blah = false;
[/code]

Thanks in advance.
Link to comment
https://forums.phpfreaks.com/topic/35000-array-question/
Share on other sites

did this test to try it
[code]
<?php
$blah = array('w', 'r', 't');
print_r($blah);
echo" <br>first bit done <br>";
$blah = false;
print_r($blah);
echo" second bit done <br>";
?>
[/code]
and got the following
[quote]
Array ( [0] => w [1] => r [2] => t )
first bit done
second bit done
[/quote]

so it seems to delete the instance of array completley
Link to comment
https://forums.phpfreaks.com/topic/35000-array-question/#findComment-165077
Share on other sites

just wanted to point out that even though it "erases" the contents of the array, it does not destroy the array.  It is still set: to false. So if you did this:

[code]
  $blah = array('w', 'r', 't');
  print_r($blah);
  echo" <br>first bit done <br>";
 
  $blah = false;
 
  if (isset($blah)) {
      echo "blah is set";
  }
?>
[/code]

"blah is set" would echo. if you were aiming to completely destroy the array, do unset($blah);

[code]
<?php

  $blah = array('w', 'r', 't');
  print_r($blah);
  echo" <br>first bit done <br>";

$blah = false;

if (isset($blah)) {
    echo "blah is set<br>";
}
  echo" 2nd bit done <br>";

unset($blah);
if (isset($blah)) {
    echo "blah is set<br>";
}

  echo" 3rd bit done <br>";

?>
[/code]
the 2nd condition would be false.
Link to comment
https://forums.phpfreaks.com/topic/35000-array-question/#findComment-165083
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.