Why does this PHP code just echo Array ?
You are calling echo
on an actual array, which does not have an implicit string representation.
In order to output an array's contents you can use the print_r
, var_dump
or var_export
functions or for custom output, you can use array_map
or even a foreach
loop:
print_r($errormessage);
var_dump($errormessage);
var_export($errormessage);
foreach($errormessage as $error)
echo $error . '<br/>';
array_map('echo', $errormessage);
Why does the Code only show 'array'
There are 2 mistakes:
$word=Hello World;
should be$word='Hello World';
You are echoing an array; do
print_r ($first_fifty);
instead;All the code:
<?php
$word='Hello World';
$words = str_word_count($word, 1,'ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ');
$len = min(50, count($words));
$first_fifty = array_slice($words, 0, $len);
print_r ($first_fifty);
?>
You can echo:
<?php
echo $first_fifty[0] . ' ' . $first_fifty[1];
?>
How can I echo or print an array in PHP?
This will do
foreach($results['data'] as $result) {
echo $result['type'], '<br>';
}
PHP - PDO echo $array['name']; is not working
foreach ($places as $place) {
echo $places['Street'];
echo $places['Number'];
echo $places['City'];
echo $places['Country'];
}
replace by
foreach ($places as $place) {
echo $place['Street'];
echo $place['Number'];
echo $place['City'];
echo $place['Country'];
}
Use fetch
instead of fetchAll
in your while loop
Hope it solves your problem
PHP echo returning the word 'Array'
echo
will print a string, try using something like print_r()
or var_dump()
instead
Example
echo '<pre>';
print_r($result_array);
echo '</pre>';
<pre>
will allow for easier reading of the array
PHP How to Echo Across the Whole Page
Don't mess with the element class lists. Use CSS files to apply the colours you want.
Start with a basic CSS design file:
p {
margin-left:10px
font-size: 12pt;
}
h1 {
font-size: 24pt;
}
div {
margin: 10px;
padding 20px;
}
Then create CSS colour files with different colour selections:
blue.css
p {
color:blue;
}
h1 {
color: darkblue;
background-color: lightblue;
}
red.css
p {
color:red;
}
h1 {
color: maroon;
background-color: pink;
}
default.css
p {
color:black;
}
h1 {
color:white;
background-color:black;
}
Then load the colour theme you want
<?php
if (isset($_COOKIE['theme'] && in_array($_COOKIE['theme'], ['red','blue'])) {
$themeCSS = '<link rel="stylesheet" href="'.$_COOKIE['theme'].'.css">';
} else {
$themeCSS = '<link rel="stylesheet" href="default.css">';
}
Then echo $themeCSS
in your <head>
just like any other <head>
element
** I've used standard HTML elements here to illustrate, but any CSS selectors should work.
PHP echo $array[$i] not showing anything
Maybe now your browser is trying to render the html output and it just result in a "blank page".
Did you try the "view source" option?
Related Topics
Pg_Query Result Contains Strings Instead of Integer, Numeric
Preg_Match() Unknown Modifier '[' Help
I Cannot Use MySQL_* Functions After Upgrading PHP
Best Way to Allow Plugins for a PHP Application
What Are the Differences Between Psr-0 and Psr-4
Understanding Ioc Containers and Dependency Injection
How to Throttle My Site's API Users
How to Create Static Classes in PHP (Like in C#)
How to Easily Switch Between PHP Versions on MAC Osx
What Does Double Question Mark () Operator Mean in PHP
Skip First Line of Fgetcsv Method
PHP Code to Test Pdo Is Available
Using Nulls in a MySQLi Prepared Statement
How to Split a String in PHP at the Nth Occurrence of a Needle