Page 1 of 1

Remove Array Text on Array PHP Codes Output

Posted: Sun Apr 11, 2010 6:03 pm
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..

Re: Remove Array Text on Array PHP Codes Output

Posted: Sun Apr 11, 2010 6:15 pm
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!?

Re: Remove Array Text on Array PHP Codes Output

Posted: Sun Apr 11, 2010 7:24 pm
by requinix
Rather than try some screwy method, do something reasonable:

Print the array contents yourself.

Re: Remove Array Text on Array PHP Codes Output

Posted: Mon Apr 12, 2010 6:37 am
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