나는 내 코드에 문제가있어 잘 이해할 수있을 것이다. 주된 목적은 으로 그 값에 따라 배열을 정렬 한 다음 (숫자 키를 다시 색인화)입니다.PHP 배열에서 값의 유형을 변경하고 그것을 정렬하는 방법 .. 가능합니까?
$filename = array("index 198.php", "index 192.php", "index 144.php", "index 2.php", "index 1.php", "index 100.php", "index 111.php");
$alloutput = array(); //all of index in array
foreach ($filename as $name) {
preg_match('#(\d+)#', $name, $output); // take only the numerical from file name
array_shift($output); // cleaned. the last code create duplicate numerical in $output,
if (is_array($output)) {
$alloutput = array_merge($alloutput, $output);
}
}
//try to check the type of every value in array
foreach ($alloutput as $output) {
if (is_array($output)) {
echo "array true </br>";
} elseif (is_int($output)) {
echo "integer true </br>";
} elseif (is_string($output)) { //the numerical taken from filename always resuld "string".
echo "string true </br>";
}
}
코드의 출력이 될 것이다 :
배열 ( [0] => 198
나 파일명의 샘플을 얻었다 [1] => 192 [2] => 144 [3] => 2 [4] => 1 [5] => 100 [6] => 111 )
제가 테스트가 어레이의 모든 출력. 그것은 모든 문자열 (숫자가 아님)입니다. 따라서이 문자열을 정수로 변경하는 방법은 입니다. 가장 낮은 숫자부터 높은 숫자까지 정렬 할 수 있습니까?
이 코드의 주된 목적은 정렬이 가장 낮은 곳에서 가장 높은 곳으로 배열을 출력하는 방법입니까?
난 당신의 코드를 이해하지 않는, 당신의 루프 (hasil 및 hasilku) –
니콜로에서 정의되지 않은 바르가, 나는 매우 죄송합니다. 나는 그것을 바꾸려고 노력할 것이다 – justjoe