English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I only want to data and do not want to loop.
$test = (1,2,3,4);

print_r($test) will print the data and the key, but I just want to output to be 1234

2007-11-28 10:48:30 · 4 answers · asked by Tasm 6 in Computers & Internet Programming & Design

4 answers

$test = (1,2,3,4) isn't proper in PHP. It is supposed to be:

$test = array(1,2,3,4)

You have several ways to print out as 1234:

a) Foreach (example on http://www.php.net/foreach)

foreach($test as $key=>$value) {
echo $value;
}

b) While-Loop (example on http://www.php.net/foreach)

while (list($key, $value) = each($test)) {
echo $value;
}

c) Implode (example on http://www.php.net/implode)

echo(implode("", $test));

2007-11-28 13:52:47 · answer #1 · answered by WordToTheWise 2 · 0 0

$a = array (10=>1, 11=>2, 12=>3, 13=>4);
$arr= print_r( array_values($a), TRUE );

$arr = eregi_replace("Array \(*\)", "", $arr);
$arr = eregi_replace("\[[0-9]*\] => ", "", $arr);
$arr = eregi_replace("[^0-9]", "", $arr);

echo $arr . "
";
?>
That will give you the output without the Array ( [0] => 1....

It stores just the array values into a new array, then it converts it to a string when it is doing the regular expression replacement. The next regular expression removes all of the keys and arrows. The final regular expression removes the spaces.

Any more questions about it let me know.

2007-11-28 22:36:59 · answer #2 · answered by madludwigv 2 · 0 0

You have to use a loop to convert your array to a string if you want your output to be without commas.

2007-11-28 19:11:38 · answer #3 · answered by Enigmatism 2 · 0 0

php print_r() function is used for the print the array ..... Demo :

2014-04-15 10:03:59 · answer #4 · answered by tutorials 1 · 0 0

fedest.com, questions and answers