-1

I'm getting the error:

Can't use function return value in write context

when trying to use this function call:

<?php if ( get_price( item_1 ) = 100) { ?>
Hello
<?php } else { } ?> 

This is the function:

function get_price($m) {

global $item,$i;    

  if ($m == "item_1") {
    $value =  $item[$i]["a_price"];
  }  
  else { 
    $value = $item[$i]["price"];
  }

  return $value;

}

The function DOES work when I do something like this though:

<?= get_total_price( item_1 ) ?>

Or when I use != Operator like:

<?php if ( get_price( item_1 ) != 100) { ?>

So I have no clue what's the problem with this specific use

chris85
  • 23,846
  • 7
  • 34
  • 51
rockyraw
  • 1,125
  • 2
  • 15
  • 36
  • 1
    `=` is not a comparison it sets. So `get_price( item_1 ) = 100` is incorrect. You are trying to set the function to 100 with your current code, not possible. – chris85 Oct 09 '16 at 16:28
  • How does `!=` works fine though? I noticed it check the value correctly, even though I'm not using `!==` – rockyraw Oct 09 '16 at 16:33
  • Because `!=` says `not equal to`, Where as `==` says `equal to`, and`=` says `set`. `===` and `!==` says the same but compare the type as well. – chris85 Oct 09 '16 at 16:47

1 Answers1

0

You have mistake in line

<?php if ( get_price( item_1 ) = 100) { ?>

It should be one more equals (=) and one more (

<?php if ( get_price( item_1 ) == 100)) { ?>
zuchol
  • 26
  • 2