Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Remove PHP Array Implode Character from Beginning of String
    primarykey
    data
    text
    <p>I am working on a project that requires imploding an array with character separation. I have successfully used <code>join</code> and <code>implode</code> interchangeably in other parts of the project, but I can't get it to work in this section. </p> <pre><code>$dbQuery = "SELECT ftc.*, fc.name FROM facilities f LEFT JOIN facility_to_category ftc ON f.fid = ftc.fid LEFT JOIN facility_categories fc ON ftc.cid = fc.cid WHERE f.listing_year = '2011' AND fc.parent_cid = '2' AND f.fid = ('".$listing_fid."')"; $dbResult = $dbc-&gt;query($dbQuery,__FILE__,__LINE__); $num_results = $dbc-&gt;num_rows($dbResult); echo '&lt;h3&gt;Demographics&lt;/h3&gt; &lt;div&gt;'; while($catdata = $dbc-&gt;fetch($dbResult)) { $demographics = array(); $demographic_names = array('',trim($catdata-&gt;name)); $demographics = implode(' '.chr(149).' ',$demographic_names); print $demographics; } </code></pre> <p>The result is this: </p> <pre><code>Demographics • Affluent • Children • Hard-to-Reach • Parents </code></pre> <p>instead of </p> <pre><code>Demographics Affluent • Children • Hard-to-Reach • Parents </code></pre> <p>I've tried using double quotes instead of single quotes around '.chr(149).'. I've tried using commas or bars or just spaces. I've tried different ways of trimming and not trimming <code>$catdata-&gt;name</code>. </p> <p>I also thought about trying string concatenation, but then I'll end up with an extra character at the end instead of the beginning. <code>Implode</code> or <code>join</code> seem the better way to go.</p> <p>What am I missing?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload