PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
saiijin_nxtoyou
Forum Newbie
Posts: 2 Joined: Sun Apr 11, 2010 5:58 pm
Post
by saiijin_nxtoyou » Sun Apr 11, 2010 6:03 pm
Code: Select all
<?php
// Create a simple array.
$array = array(1, 2, 3, 4, 5);
print_r($array);
// Now delete every item, but leave the array itself intact:
foreach ($array as $i => $value) {
unset($array[$i]);
}
print_r($array);
// Append an item (note that the new key is 5, instead of 0).
$array[] = 6;
print_r($array);
// Re-index:
$array = array_values($array);
$array[] = 7;
print_r($array);
?>
The above example will output:
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
)
Array
(
)
Array
(
[5] => 6
)
Array
(
[0] => 6
[1] => 7
)
How can I remove the text "Array" on the Output? Thanks..
lunarnet76
Forum Commoner
Posts: 67 Joined: Sun Apr 04, 2010 2:07 pm
Location: Edinburgh
Post
by lunarnet76 » Sun Apr 11, 2010 6:15 pm
hmmm something like
Code: Select all
function print_rCustom(array $array){
ob_start();
print_r($array);
$content=ob_get_clean();
echo str_replace('Array','',$array);
}
but do you just want to hide this ? It seems a bit just useless so I wonder If you are not trying to have something more complicated!?
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Sun Apr 11, 2010 7:24 pm
Rather than try some screwy method, do something reasonable:
Print the array contents yourself.