?
Solved

Setting All Values in an Array to Blank

Posted on 2011-04-25
7
Medium Priority
?
294 Views
Last Modified: 2012-08-13
Is there an easy and simply way to set all values in an array to blank?
0
Comment
Question by:deharvy
  • 4
  • 2
7 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35459404
Uhh, sure - use foreach and set them to a blank.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35459406
What do you mean by blank?  Unset, NULL, a single character space?   Give us a little more to go on and we might be able to get you a better answer.
0
 

Author Comment

by:deharvy
ID: 35459452
I definitely do not want to unset, so setting to null is more of what I want.

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1200 total points
ID: 35459464
OK, the code construct would look something like this:

foreach($array as $key => $value)
{    
    $array[$key] = NULL;
}
0
 
LVL 2

Assisted Solution

by:vogen
vogen earned 800 total points
ID: 35459591
Using array merge
http://php.net/manual/en/function.array-merge.php

<?php

$a = array("a" =>"Dog","b"=>"Cat","c"=>"Horse");
print_r($a);

$myarray = array_merge(array_diff($a, $a));

print_r($myarray);
?>
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35459676
There are some other interesting things you can do with arrays.  PHP has lots of functions, and all of them are documented on the PHP.net web site, with examples and user-contributed notes.   Have a look at the functions listed in the left sidebar here:
http://php.net/manual/en/function.range.php
0
 

Author Closing Comment

by:deharvy
ID: 35459947
Thanks for your help!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question