PHP
--
Questions
--
Followers
Top Experts
I keep getting the following error in my apache logs: "PHP Warning: implode(): Argument must be an array". I presume it is because the array is empty or does not have enough content. Can somebody give some advice on how to get rid of the warnings. It seems to function fine.
$sentences = $content->getSentences();
$chunks = array_chunk($sentences, count($sentences) / 2);
$sections = array_chunk($chunks[0], count($chunks[0]) / 7);
$main_content = implode($chunks[1]);
$section1 = implode($sections[0]);
$section2 = implode($sections[1]);
$section3 = implode($sections[2]);
$section4 = implode($sections[3]);
$section5 = implode($sections[4]);
$section6 = implode($sections[5]);
$section7 = implode($sections[6]);
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
$x = array("The","quick","brown
echo implode("#",$x); // Results in "The#quick#brown#fox"
echo implode(" ",$x); // Results in "The quick brown fox"
$string = "The quick brown fox";
$array = explode(" ",$string); // Results in Array("The","quick","brown
The implode/explode functions are pretty useful for any kind of delimited strings or to find the individual lines in a piece of content (explode() the whole contents by the newline \n character)






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
$main_content = implode("",$chunks[1]);
$main_content = implode(NULL,$chunks[1]);
Before your script uses a function that requires an array for input you can test the input data to see if it is an array. (#protip: All PHP functions are documented in the PHP.net web site -- required reading if you're going to try to write programs in PHP).
http://php.net/manual/en/function.is-array.php
A really good book to help you get a jump-start in PHP...
http://www.sitepoint.com/books/phpmysql5/
PHP Warning: implode(): Argument must be an array

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
I got it to work by checking for null...The correct way would be to check to see if the data element is an array. Many PHP functions return an array on success or FALSE on failure. A test for NULL will fail both of those conditions. Use this function instead (see comment at ID: 38192318 for the explanation).
http://php.net/manual/en/function.is-array.php






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
PHP
--
Questions
--
Followers
Top Experts
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.