저는 PHP에 익숙하지 않으므로 전에 기본 질문을하고 있다면 묻습니다. 나는 며칠 동안 이걸 봤는데 이제는 봤어. 이 포럼에서는 대부분의 이전 답변을 찾았지만이 문제에 대해서는 아무 것도 찾을 수 없으므로 물어봐야합니다. 이것이 나의 첫 번째 질문이다.하위 배열을 확인란으로 배열로 다른 페이지로 전달할 수 있습니까?
// this array is coming from MySQL db as a result. It's a list of user's friends and it could contain dozens or hundreds of friends. Now he wants to put them in different groups.
$array = array(
array("John", "Doe", "1"),
array("Peter", "Citizen", "2")
...
);
// a page is created with the result. Each record has a checkbox that the user can select.
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<?php
foreach($array as $item){
$nItem = $item;
?>
<input type="text" name="fname" value="<?php if(isset($nItem)){echo $nItem[0];} ?>" readonly="readonly" />
<input type="text" name="lname" value="<?php if(isset($nItem)){echo $nItem[1];} ?>" readonly="readonly" />
<input type="text" name="uid" value="<?php if(isset($nItem)){echo $nItem[2];} ?>" readonly="readonly" />
<input type="checkbox" name="val[]" value="<?php if(isset($nItem)){echo $nItem;} ?>" /> // I want to send this $nItem array as it is to the action page and read its keys and values there.
<br>
<?php
}
?>
<input type="submit" name="submit" value="Submit">
</form>
<br />
<?php
// if I tick both checkboxes and submit I get the following:
if(isset($_POST['val'])){
$val = $_POST['val'];
echo var_dump($val), '<br />'; // array(2) { [0]=> string(5) "Array" [1]=> string(5) "Array" }
echo count($val), '<br />'; // 2
print_r($val); // Array ([0] => Array [1] => Array)
echo("val is {$val[0]}"); // val is Array
foreach($val as $key => $value){
echo "Key and Value are: ".$key." ".$value, '<br />'; // Key and Value are: 0 Array
} // Key and Value are: 1 Array
}
?>
나는 velues를 읽을 수있는 실제 배열 대신 "Array"라는 문자열을 반환합니다.
if(isset($nItem)){echo "".$nItem[0]." ".$nItem[1]." ".$nItem[2]."";}
- - 나는 다음과 같은 체크 박스 값의 개별 값을 넣으면
0 John Doe 1
을 - - 그때 얻을 수 있지만 내가 원하는 게 아니에요. 내가 반복 할 수있는 액션 페이지의 실제 배열을 원한다. 나는 그것이 이미 배열 이었기 때문에 어렵지 않을 것이라고 생각했지만 틀렸어.
아무에게도 어떻게 할 수 있습니까?
미리 감사드립니다.