나는 PHP
. 그러니 참아주세요. 나는 db에서 노래를 가져와야한다. 나는 방법을 모르는 for 루프에 연관 배열을 초기화 하여 keyValuePair.
도 그것에 상태 속성을 추가 할 수 있습니다.
내가 원하는 것은
{
"status" : "true" ,// It tells whether day available or not
"data": [
{
"name": "Joe Bloggs",
"id": "203403465"
},
{
"name": "Fred Bloggs",
"id": "254706567"
},
{
"name": "Barny Rubble",
"id": "453363843"
},
{
"name": "Homer Simpson",
"id": "263508546"
}
]
}
내 코드
$html = file_get_html('http://1stfold.com/taskbox/Farrukh/Zare/');
$output = array();// how to initialze it in for loop with keyValue pair
// Find all "A" tags and print their HREFs
foreach($html->find('.branded-page-v2-body a') as $e)
{
if (0 === strpos($e->href, '/watch?v'))
{
$output[] = $e->href . '<br>';
echo $e->href . '<br>';
}
}
echo json_encode($output);
미리 감사드립니다.
간단히 다음을 변경하여 $ output 배열에 배열을 추가 할 수 있습니다.
$output[] = $e->href . '<br>';
이에 :
$output['data'][] = array('name' => $name_value, 'id' => $id_value);
그러면 배열이 $ output [ 'data'] 배열로 푸시됩니다.
루프 앞에 "status"keyValuePair를 추가해야합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다