Colby
Colby

Reputation: 296

echo array without last item in php

Does anyone know how to not echo the last item in an array? I'm really new to php.

Here is the part I'm having trouble with:

...

return($keywords);

}

$words = (mixer(strtolower($keywordlist)));
$query =  implode(',', $words);
echo('Search query: ' . $query . PHP_EOL);
$query = rawurlencode($query);
echo('Encoded: ' . $query . PHP_EOL);
***trying to remove last item in array from showing here***
echo('Without Last: ' . $query . PHP_EOL);

If I put array_shift($query); or array_pop($query); or array_shift($array,1,-1)); were the stars are I get this error:

Parse error: syntax error, unexpected T_ECHO in /home/content/14/7557914/html/test2.php on line 102 
line 102 = echo('Without Last: ' . $query . PHP_EOL);  

What am I doing wrong?

Upvotes: 1

Views: 438

Answers (1)

John Green
John Green

Reputation: 13435

Because you don't have an array. You already imploded it, so it is a string. You'd need to array_pop($words), then implode(',',$words).... not $query.

Upvotes: 5

Related Questions