how can i get value from inside of function?

前端 未结 4 1275
感情败类
感情败类 2021-01-23 02:35

Is it possible to get those values inside of function and use those outside of function here is my code:



        
4条回答
  •  半阙折子戏
    2021-01-23 02:44

    You need to "return" the value. See the entry in the PHP manual for this. Basically, return means "exit this function now". Optionally, you can also provide some data that the function can return.

    Just use the return statement:

     $value) {
              if ($value > 0) {
                  if (substr($name, 0, 5) == 'cart_') {
                      $id = substr($name, 5, (strlen($name) - 5));
                      $get = mysql_query('SELECT id, name, price FROM products WHERE id=' . mysql_real_escape_string((int)$id));
                      while ($get_row = mysql_fetch_assoc($get)) {
                          $sub = $get_row['price'] * $value;
                          echo $get_row['name'] . ' x ' . $value . ' @ £' . number_format($get_row['price'], 2) . ' = £' . number_format($sub, 2) . '[-] [+] [Delete]
    '; } } $total += $sub; } } return $total; } ?>

提交回复
热议问题