1
私は親の名前に基づいて質問セットと親セットを持っています。質問のanswerOptionを読んで行列のような文字列を作成したいと思います。結果はすべての可能性の組み合わせになります。私は配列の値を持つ文字列を作成
以下key=524136910&CurrentInsuranceStatus=Y&InsuredTimeframe=-1
key=524136910&CurrentInsuranceStatus=Y&InsuredTimeframe=FiveYearsorMore
...
key=524136910&CurrentInsuranceStatus=Parents&InsuredTimeframe=-1
key=524136910&CurrentInsuranceStatus=Parents&InsuredTimeframe=FiveYearsorMore
次のように結果の文字列を書きたい
は私のコードが、文字列で、その繰り返しの親です。 例CurrentInsuranceStatusこれは親であり、=記号の後に以下
public function createCBQJson($questions,$parents)
{
$cbqStdObj = $parents;
$jsonString = '';
$urlArr = array();
foreach($cbqStdObj as $key=>$val)
{
if(!in_array($key, array('DriverOccupation')))
{
//continue;
}
$jsonString = $key;
if(isset($val->k))
{
$cbqKey = $val->k;
}
// echo 'parents of -'.$jsonString.'--<br>';
$cbqUrl = '';
if(isset($val->p) && count($val->p)>=2)
{
foreach($val->p as $pkey=>$pval)
{
//create url with parent
$answers = $questions[$pval]['QuestionData']->_answerOptions;
if(count($answers) > 0)
{
foreach($answers as $ansKey=>$ansValue)
{
$cbqUrl.= '?key='.$cbqKey.'&'.$pval.'='.$ansValue->_value ;
}
}
}
$cbqSet[$cbqKey] = $cbqUrl;
}
}
}
に答えるのは、あなたが取得するためのコードの下に使用することができます質問は以下
Array
(
[CurrentInsuranceStatus] => Array
(
[QuestionData] => Platform_Form_Page_Question Object
(
[_answer] =>
[_answerOptions] => Array
(
[0] => Platform_Form_Page_Question_AnswerOption Object
(
[_answerKey] => 340280
[_hideAnswer] =>
[_order] => 110
[_promptText] => Yes
[_value] => Y
[_errorLog] => Array
(
)
)
[1] => Platform_Form_Page_Question_AnswerOption Object
(
[_answerKey] => 340290
[_hideAnswer] =>
[_order] => 120
[_promptText] => Yes, on parents policy
[_value] => Parents
[_errorLog] => Array
(
)
)
[2] => Platform_Form_Page_Question_AnswerOption Object
(
[_answerKey] => 340300
[_hideAnswer] =>
[_order] => 130
[_promptText] => Yes, insured through employer
[_value] => Company
[_errorLog] => Array
(
)
)
[3] => Platform_Form_Page_Question_AnswerOption Object
(
[_answerKey] => 340310
[_hideAnswer] =>
[_order] => 140
[_promptText] => No, policy lapsed/expired
[_value] => Lapsed
[_errorLog] => Array
(
)
)
[4] => Platform_Form_Page_Question_AnswerOption Object
(
[_answerKey] => 340320
[_hideAnswer] =>
[_order] => 150
[_promptText] => No, never been insured
[_value] => Never
[_errorLog] => Array
(
)
)
[5] => Platform_Form_Page_Question_AnswerOption Object
(
[_answerKey] => 340330
[_hideAnswer] =>
[_order] => 160
[_promptText] => No, I didnt have a vehicle to insure
[_value] => First
[_errorLog] => Array
(
)
)
[6] => Platform_Form_Page_Question_AnswerOption Object
(
[_answerKey] => 340340
[_hideAnswer] =>
[_order] => 170
[_promptText] => No, been deployed/overseas in the military
[_value] => Military
[_errorLog] => Array
(
)
)
[7] => Platform_Form_Page_Question_AnswerOption Object
(
[_answerKey] => 340350
[_hideAnswer] =>
[_order] => 180
[_promptText] => No, other reason
[_value] => Other
[_errorLog] => Array
(
)
)
)
[_answersDivID] => html_CurrentInsuranceStatus
[_phoneAreaField] =>
[_attributeName] => CurrentInsuranceStatus
[_criteriaBasedQuestion] => 1
[_dateField] =>
[_eventHandler] =>
[_fieldType] => select
[_hideQuestion] => 1
[_monthField] =>
[_phoneNumberField] =>
[_order] => 10010
[_pageAttributes] => stdClass Object
(
[additionalLabel] =>
[answerStyle] =>
[colNum] =>
[colWidth] =>
[cssclass] =>
[defaultValue] =>
[isMultiSelect] =>
[maxLength] =>
[min] =>
[questionSkinStyle] =>
[toolTip] =>
)
[_phonePreFixField] =>
[_questionDivID] => prompt_CurrentInsuranceStatus
[_questionKey] => 7520910
[_required] => 1
[_text] => Current insurance status
[_yearField] =>
[_errorLog] => Array
(
)
)
)
[InsuredTimeframe] => Array
(
[QuestionData] => Platform_Form_Page_Question Object
(
[_answer] =>
[_answerOptions] => Array
(
[0] => Platform_Form_Page_Question_AnswerOption Object
(
[_answerKey] => 3063810
[_hideAnswer] =>
[_order] => 100
[_promptText] => Please Select
[_value] => -1
[_errorLog] => Array
(
)
)
[1] => Platform_Form_Page_Question_AnswerOption Object
(
[_answerKey] => 653710
[_hideAnswer] =>
[_order] => 110
[_promptText] => 5 years or more
[_value] => FiveYearsorMore
[_errorLog] => Array
(
)
)
[2] => Platform_Form_Page_Question_AnswerOption Object
(
[_answerKey] => 653810
[_hideAnswer] =>
[_order] => 120
[_promptText] => 4-5 years
[_value] => FourtoFiveYears
[_errorLog] => Array
(
)
)
[3] => Platform_Form_Page_Question_AnswerOption Object
(
[_answerKey] => 654110
[_hideAnswer] =>
[_order] => 130
[_promptText] => 3-4 years
[_value] => ThreetoFourYears
[_errorLog] => Array
(
)
)
[4] => Platform_Form_Page_Question_AnswerOption Object
(
[_answerKey] => 654310
[_hideAnswer] =>
[_order] => 140
[_promptText] => 2-3 years
[_value] => TwotoThreeYears
[_errorLog] => Array
(
)
)
[5] => Platform_Form_Page_Question_AnswerOption Object
(
[_answerKey] => 654210
[_hideAnswer] =>
[_order] => 150
[_promptText] => 1-2 years
[_value] => TwelveOrMoreMonths
[_errorLog] => Array
(
)
)
[6] => Platform_Form_Page_Question_AnswerOption Object
(
[_answerKey] => 654010
[_hideAnswer] =>
[_order] => 160
[_promptText] => 6 to 11 months
[_value] => SixToElevenMonths
[_errorLog] => Array
(
)
)
[7] => Platform_Form_Page_Question_AnswerOption Object
(
[_answerKey] => 653910
[_hideAnswer] =>
[_order] => 170
[_promptText] => Less than 6 months
[_value] => LessThanSixMonths
[_errorLog] => Array
(
)
)
)
[_answersDivID] => html_InsuredTimeframe
[_phoneAreaField] =>
[_attributeName] => InsuredTimeframe
[_criteriaBasedQuestion] => 1
[_dateField] =>
[_eventHandler] =>
[_fieldType] => select
[_hideQuestion] => 1
[_monthField] =>
[_phoneNumberField] =>
[_order] => 10020
[_pageAttributes] => stdClass Object
(
[additionalLabel] =>
[answerStyle] =>
[colNum] =>
[colWidth] =>
[cssclass] =>
[defaultValue] =>
[isMultiSelect] =>
[maxLength] =>
[min] =>
[questionSkinStyle] =>
[toolTip] =>
)
[_phonePreFixField] =>
[_questionDivID] => prompt_InsuredTimeframe
[_questionKey] => 7169110
[_required] => 1
[_text] => How long have you been continuously insured?
[_yearField] =>
[_errorLog] => Array
(
)
)
)
)
をarrray親配列
stdClass Object
(
[IncidentClaimAmountPaid] => stdClass Object
(
[o] => 13520
[k] => 524136910
[p] => Array
(
[0] => CurrentInsuranceStatus,
[1] => InsuredTimeframe
)
[e] =>
[r] => 1
[a] => Array
(
[0] => stdClass Object
(
[i] => 32
[k] => 529582210
[p] => Array
(
[0] => IncidentClaimLabel
)
[e] =>
)
[1] => stdClass Object
(
[i] => 1
[k] => 529580710
[p] => Array
(
[0] => IncidentClaimLabel
)
[e] =>
)
[2] => stdClass Object
(
[i] => 4
[k] => 529581310
[p] => Array
(
[0] => IncidentClaimLabel
)
[e] =>
)
[3] => stdClass Object
(
[i] => 2
[k] => 529581010
[p] => Array
(
[0] => IncidentClaimLabel
)
[e] =>
)
[4] => stdClass Object
(
[i] => 16
[k] => 529581910
[p] => Array
(
[0] => IncidentClaimLabel
)
[e] =>
)
[5] => stdClass Object
(
[i] => 128
[k] => 529582810
[p] => Array
(
[0] => IncidentClaimLabel
)
[e] =>
)
[6] => stdClass Object
(
[i] => 64
[k] => 529582510
[p] => Array
(
[0] => IncidentClaimLabel
)
[e] =>
)
[7] => stdClass Object
(
[i] => 256
[k] => 530551610
[p] => Array
(
[0] => IncidentClaimLabel
)
[e] =>
)
[8] => stdClass Object
(
[i] => 8
[k] => 529581610
[p] => Array
(
[0] => IncidentClaimLabel
)
[e] =>
)
)
)
)