저는 프로그램에 약간의 문제가 있으며 PHP에는별로 경험이 없습니다. html 형식의 객체 배열을 PHP 파일로 전송하려고합니다. 당신은 내가 만 입력 숨겨진 가치의 배열을 인쇄하는 것을 볼 수 있습니다html 형식의 객체 배열을 전송할 수 없습니다.
<form action="action/add_items.php" method="POST">
<table border="1" width="20%">
<thead>
<th>
<?= $lang["location_task"][$location->getProperty("location_id")][$location_task->getProperty("location_task_id")]; ?>
</th>
</thead>
<tbody>
<?php
$location_task_items = $location_task->getProperty("location_task_items");
foreach ($location_task_items as $location_task_item) {
?>
<tr>
<td>
<?= $lang["item"][$location_task_item->getProperty("location_task_item_id")]; ?>
</td>
<td>
<?= $location_task_item->getProperty("location_task_item_value"); ?>
</td>
</tr>
<?php
}
?>
<tr>
<td></td>
<td>
<input type="hidden" value="<?php print_r($location_task_items); ?>" name="location_task_items"/>
<input type="submit" value="start"/>
</td>
</tr>
</tbody>
</table>
</form>
을
location.php (실행 파일 형태의) : 우선 난 당신이 내 코드에 대해 살펴 보겠습니다됩니다. 그게 맞습니까?
add_items.php
$location_task_items = $_REQUEST["location_task_items"];
foreach($location_task_items as $location_task_item) {
if($Player_Has_ItemsClass->getObjectByIds($player_id, $location_task_item->getProperty("location_task_item_id")) == null) {
$player_has_items_attributes = array();
$player_has_items_attributes["player_has_items_player_id"] = $player_id;
$player_has_items_attributes["player_has_items_item_id"] = $location_task_item->getProperty("location_task_item_id");
$player_has_items_attributes["player_has_items_item_value"] = $location_task_item->getProperty("location_task_item_value");
$player_has_items = new Player_Has_Items($player_has_items_attributes);
$Player_Has_ItemsClass->insertObject($player_has_items);
} else {
}
}
난 단지 문자열로 배열 add_items.php에서 foreach 문에이 예외 얻을 : 나는 또한로 json_encode과 json_decode과 그것을 시도
Invalid argument supplied for foreach()
를 :
print_r(json_encode($location_task_items))
json_decode($_REQUEST["location_task_items"]);
하지만 get (object attribu TES)를 공개했다 : 당신을 위해
Call to undefined method stdClass::getProperty()
덕분에 당신은 할 수 :
그런 식으로 배열을 인쇄 할 수 없습니다. 또한, 나는'print_f'가 일이라고 생각하지 않습니다 ... – imtheman
배열을 문자열로 얻으려면 쉼표로 구분합니까? 그렇다면 PHP 디버그 함수를 찾으십시오. – user3479671
"Array ([0] => Location_Task_Item 객체 ([location_task_item_id] => 100 [location_task_item_value] => 10))"하지만 "is_array"는 false를 표시합니다. . –