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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.