Remove Array Text on Array PHP Codes Output

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

Post Reply
saiijin_nxtoyou
Forum Newbie
Posts: 2
Joined: Sun Apr 11, 2010 5:58 pm

Remove Array Text on Array PHP Codes Output

Post by saiijin_nxtoyou »

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

Re: Remove Array Text on Array PHP Codes Output

Post by lunarnet76 »

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);
}
:drunk:
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!?
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Remove Array Text on Array PHP Codes Output

Post by requinix »

Rather than try some screwy method, do something reasonable:

Print the array contents yourself.
roders
Forum Commoner
Posts: 68
Joined: Tue Oct 20, 2009 9:29 am

Re: Remove Array Text on Array PHP Codes Output

Post by roders »

How about learning to display the data correctly like tasairis said.
Learn more about how to manipulate arrays.
http://php.net/manual/en/language.types.array.php
Post Reply