嘿,我有这个数组:
array(1) {
["dump"]=>
string(38) "["24.0",24.1,24.2,24.3,24.4,24.5,24.6]"
}
Run Code Online (Sandbox Code Playgroud)
我的问题:
如何从这个数组中获取第一个和最后一个元素,所以我将:
$firstEle = "24.0";
Run Code Online (Sandbox Code Playgroud)
和
$lastEle = "24.6";
Run Code Online (Sandbox Code Playgroud)
谁知道如何从阵列中获取这些元素?
我已经尝试过了:
$arr = json_decode($_POST["dump"], true);
$col0 = $arr[0];
$col1 = $arr[1];
$col2 = $arr[2];
$col3 = $arr[3];
$col4 = $arr[4];
$col5 = $arr[5];
$col6 = $arr[6];
Run Code Online (Sandbox Code Playgroud)
我可以选择$ col0和$ col6,但是数组可能要长得多,所以需要一种方法来过滤第一个("24.0")和最后一个("24.6")元素.问候
我的图片上传过程中出现了疑似问题,我会告诉你:
<form action="check.php" method="POST">
File: <input type="file" name="picture" value="" id="picture-field">
<span class="error" id="file-error"></span>
<br><br>
<input type="submit" name="submit" value="send">
</form>
Run Code Online (Sandbox Code Playgroud)
我的check.php:
require 'ImageChecker.php';
if (!$_FILES)
echo "exit because no FILES";
$imageChecker = new ImageChecker();
$imageError = "";
if(!$imageChecker->php_error($_FILES['picture']['error'])) {
$imageError = "php error ocurred!";
echo $imageError;
Run Code Online (Sandbox Code Playgroud)
ImageChecker.php类:
class ImageChecker {
// function for php-error-check
public function php_error ($php_error) {
if ($php_error === UPLOAD_ERR_OK) {
return TRUE;
} else {
return FALSE;
}
}
// more functions..
}
Run Code Online (Sandbox Code Playgroud)
每次,我上传一张图片,我得到:
exit because no …Run Code Online (Sandbox Code Playgroud) 我需要找出差异AB的差异是否最小:
smallestDifference3 :: Int -> Int -> Int -> Int
smallestDifference a b c
| differenceAB < differenceBC < differenceAC = differenceAB
| otherwise = differenceAB
where differenceAB
| a < b = -(a - b)
| otherwise = a - b
differenceBC
| b < c = -(b - c)
| otherwise = b - c
differenceAC
| a < c = -(a - c)
| otherwise = a - c
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
cannot mix `<' [infix 4] and `<' …Run Code Online (Sandbox Code Playgroud) 我有这个小爆炸过程:
$var = 120.180;
$var = explode("." , $var);
$var1 = $var[0];
$var2 = $var[1];
echo $var1;
echo $var2;
Run Code Online (Sandbox Code Playgroud)
回声是:
120和18,为什么?为什么180变为18,我该如何解决?