What's wrong with this PHP code? [closed]

-3
if(count($items) > 1) {
    $out = array('success'=>false,'error'=>'You choose more bots');
} elseif($user['balance'] < $sum) {
    $out = array('success'=>false,'error'=>'You dont have coins! You have' echo $user['xxx']);
    
asked by anonymous 09.07.2017 / 17:28

2 answers

5

I do not think you need to put echo , try doing it this way:

$out = array('success'=>false,'error'=>'You dont have coins! You have'.$user['xxx']);

Also try double quotation marks instead of single quotation marks:

$out = array('success'=>false,'error'=>"You dont have coins! You have {$user['xxx']}");
    
09.07.2017 / 17:33
0

There are 2 errors in this code, besides there is a echo in the string, the closure of the elseif tag is also missing. After $sum) has the opening { , but the closing - > } is missing. The correct code would be:

<?php

if( count($items) > 1)
{
    $out = array(
        'success' => false,
        'error'   => 'You choose more bots'
    );
}
elseif($user['balance'] < $sum)
{
    $out = array(
        'success' => false,
        'error'   => "You dont have coins! You have ${user['xxx']}" // <-- Estava escrito de maneira incorreta
    );
} // <-- Estava faltando

?>
  

Note : Using $user['xxx'] inside a double-quoted string will generate an error. The correct one is ${user['xxx']} or {$user['xxx']} . Note the use of the keys.

    
09.07.2017 / 23:14