2016-06-29 7 views
0

좋은 하루, 누군가 내 코드에서 잘못되었거나 잘못 코딩 한 경우를 알아 내도록 도와 줄 수 있습니까?cURL : foreach 루프의 변수

곱슬 곱슬 부분은 내 문제는 foreach 루프를 사용하여 파일을 가져 오기 시작했을 때 결과가 깨졌습니다.

배열로 사용해 보았지만 눈치 채지 못했습니다. 나는 어쩌면 내가 여기 여기

뭔가를 누락 내 코드는,이 새로운 해요 :

<?php 
$url = "http://XXXXXXXXXXXXXX"; //Base Url 
$parameters = ['mode' => 'contributors']; // riders, current_rounds, contributors, season_entries 
$ch = curl_init($url); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters); 
curl_setopt($ch,CURLOPT_HTTPHEADER, ['x-weplaymedia-authorisation:XXXXXXXXXXXXX']); 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

$result = curl_exec($ch); // Execute 

$arr = json_decode($result,true); // Dump result here. 

//print_r($arr); 

당신이 print_r($arr); 그것이 필드의 배열을 표시합니다 실행합니다.

하지만 내 foreach 루프 코드에서 특정 필드 ([fwcContributors])를 가리킬 때 깨진 이미지가 표시됩니다.

여기 here is the image of array

here is the result

은 내가 원하는 것은 [profilePicture]하고 자명에서 프로필 사진을 표시하는 결과를이다 : 여기

배열의 이미지 [userName]에서.

$i=0; 
foreach ($arr['fwcContributors'] as $val) 
{ 
if($i++ == 5); 
echo '<tbody >'; 
echo '<tr style="transform: skewX(-20deg);">'; 
echo '<td>'; 
echo '<img src='.($val['profilePicture']) .' style="transform: skewX(20deg);">' . htmlspecialchars($val['userName']); 
echo '</td>'; 
echo '</tr>'; 
} 

    ?> 

감사합니다.

답변

0

중첩 배열은 당신이 아마 ContributorList이 반복하려는, fwcContributors에 있습니다. (그들은 아무것도하지 않는 것 같이 $i 문을 툭)

foreach ($arr['fwcContributors']['ContributorList'] as $val) 
{ 
    echo '<tbody >'; 
    echo '<tr style="transform: skewX(-20deg);">'; 
    echo '<td>'; 
    echo '<img src='.($val['profilePicture']) .' style="transform: skewX(20deg);">' . htmlspecialchars($val['userName']); 
    echo '</td>'; 
    echo '</tr>'; 
} 

+0

감사 너 너무 많이. 처음에 나는 foreach ($ arr [ 'fwcContributors'] [ 'player'] [ 'contributorList']를 $ value로 시도했다.) 나는 이것을 해결할 것이라고 생각했다. 나는 너무 바보 같았다. 도와 줘서 고마워. –

+0

문제 없으니 기꺼이 도와 드리겠습니다. :) – Plenka