After printing my $my_values['outer_group']['fieldset'] I'm getting the following output as per the data:
Array
(
[fieldset] => Array
(
[1] => Array
(
[title] => Dummy_Value1
[inner_group] => Array
(
[fieldset] => Array
(
[1] => Array
(
[id] => 11
[title] => Dummy_Value11
)
[2] => Array
(
[id] => 12
[title] => Dummy_Value12
)
[3] => Array
(
[id] => 13
[title] => Dummy_Value13
)
[actions] => Array
(
[add] => Add InnerGroup
[remove] => Remove InnerGroup
)
)
)
)
[2] => Array
(
[title] => Dummy_Value2
[inner_group] => Array
(
[fieldset] => Array
(
[1] => Array
(
[id] => 21
[title] => Dummy_Value21
)
[actions] => Array
(
[add] => Add InnerGroup
)
)
)
)
[actions] => Array
(
[add] => Add OuterGroup
[remove] => Remove OuterGroup
)
)
)
My requirement is to re-index the output data, hence I've performed the following code to re-index the same:
<?php
if (isset($my_values['outer_group']) && !empty($my_values['outer_group'])) {
$outer_types = $my_values['outer_group']['fieldset'];
$inner = [];
foreach ($outer_types as $outer_key => $outer_value) {
if (is_numeric($outer_key)) {
if (isset($outer_value['inner_group']['fieldset'])) {
foreach ($outer_value['inner_group']['fieldset'] as $k => $v) {
if (is_numeric($k)) {
$inner[] = [
'id' => $v['id'],
'title' => !empty($v['title']) ? $token->replace($v['title']) : NULL,
];
}
}
}
$my_values['outer'][$outer_key] = [
'title' => !empty($outer_value['title']) ? $token->replace($outer_value['title']) : NULL,
'inner' => $inner,
];
}
}
}
As per the output its getting re-indexed but with some errors in data. I'm getting trouble while populating the [inner] data, following is the output for the same:
Array
(
[0] => Array
(
[title] => Dummy_Value1
[inner] => Array
(
[0] => Array
(
[id] => 11
[title] => Dummy_Value11
)
[1] => Array
(
[id] => 12
[title] => Dummy_Value12
)
[2] => Array
(
[id] => 13
[title] => Dummy_Value13
)
)
)
[1] => Array
(
[title] => Dummy_Value2
[inner] => Array
(
[0] => Array
(
[id] => 11
[title] => Dummy_Value11
)
[1] => Array
(
[id] => 12
[title] => Dummy_Value12
)
[2] => Array
(
[id] => 13
[title] => Dummy_Value13
)
[3] => Array
(
[id] => 21
[title] => Dummy_Value21
)
)
)
)
Whereas, it should be:
Array
(
[0] => Array
(
[title] => Dummy_Value1
[inner] => Array
(
[0] => Array
(
[id] => 11
[title] => Dummy_Value11
)
[1] => Array
(
[id] => 12
[title] => Dummy_Value12
)
[2] => Array
(
[id] => 13
[title] => Dummy_Value13
)
)
)
[1] => Array
(
[title] => Dummy_Value2
[inner] => Array
(
[0] => Array
(
[id] => 21
[title] => Dummy_Value21
)
)
)
)
$inner = []; needs to be within the foreach loop so that it is empty before building each internal element.
Untested - but as follows:
<?php
if (isset($my_values['outer_group']) && !empty($my_values['outer_group'])) {
$outer_types = $my_values['outer_group']['fieldset'];
foreach ($outer_types as $outer_key => $outer_value) {
$inner = [];
if (is_numeric($outer_key)) {
if (isset($outer_value['inner_group']['fieldset'])) {
foreach ($outer_value['inner_group']['fieldset'] as $k => $v) {
if (is_numeric($k)) {
$inner[] = [
'id' => $v['id'],
'title' => !empty($v['title']) ? $token->replace($v['title']) : NULL,
];
}
}
}
$my_values['outer'][$outer_key] = [
'title' => !empty($outer_value['title']) ? $token->replace($outer_value['title']) : NULL,
'inner' => $inner,
];
}
}
}
Related
-I cannot figure out how to regroup this array accourding to ids.
This array comes from a mysql table. the number 17 and 20 are foreign keys in the table.
$orginal_arr =
Array
(
[0] => Array
(
[id] => 17
[content] => string...?
)
[1] => Array
(
[id] => 20
[content] => hello
)
[2] => Array
(
[id] => 20
[content] => string...?
)
[3] => Array
(
[id] => 20
[content] => string...string...??
)
[4] => Array
(
[id] => 17
[content] => string...
)
[5] => Array
(
[id] => 17
[content] => string...
)
);
I want to convert the above $orginal_arr array to the following $desired_arr array.
$desired_arr = Array (
[0] => Array
(
[17] => Array
(
[0] => string...?
)
)
[1] => Array
(
[20] => Array
(
[0] => hello
[1] => string...?
[2] => string... string...??
)
)
[2] => Array
(
[17] => Array
(
[0] => string...
[1] => string...
)
)
);
so far I am trying the following approach:
function group_by_key($key, $data)
{
$result = array();
$j = 0;
foreach ($data as $val) {
if (array_key_exists($key, $val)) {
$result[$val[$key]][$j] = $val;
} else {
$result[""][] = $val;
}
$j++;
}
return $result;
}
$desired_arr = group_by_key("id", $orginal_arr);
$desired_arr2 = array();
foreach ($desired_arr as $index => $item) {
$desired_arr2 += $item;
}
echo "<pre>";
print_r($desired_arr2);
echo "</pre>";
the output:
Array
(
[0] => Array
(
[id] => 17
[content] => string...?
)
[4] => Array
(
[id] => 17
[content] => string...
)
[5] => Array
(
[id] => 17
[content] => string...
)
[1] => Array
(
[id] => 20
[content] => hello
)
[2] => Array
(
[id] => 20
[content] => string...?
)
[3] => Array
(
[id] => 20
[content] => string...string...??
)
)
- Thank you very much.
As I said in my comment, I'm not familiar to PHP syntax anymore so this will be pseudo code.
I would do it in 2 steps,
first I want this result
$temp_arr =
Array
(
[0] => Array
(
[id] => 17
[contents] => Array(
[0] => string...?
)
)
[1] => Array
(
[id] => 20
[contents] => Array(
[0] => hello
[1] => string...?
[2] => string...string...??
)
)
...
...
);
See, I kept the Object structure with id and contents (with a final S).
then it will be easier to check the id as it is directly accessible
$temp_array = Array();
foreach ($original_array as $element) {
$last = end($temp_array);
if ($last && $element->id == $last->id) {
// add to the last $temp_array element
$temp_array[count($temp_array)-1]->contents[] = $element->content;
}
else {
// create a new $temp_array element
$temp_array[] = Array(
"id" => $element->id,
"contents => Array(
$element->content
)
);
}
}
For the second step you just need to iterate the $temp_array and format as you like
here is another solution to this problem.
$desired_arr = array();
$prev_id = '';
$prev_key = null;
foreach ($orginal_arr as $key => $value) {
$this_id = $value['id'];
if ($this_id == $prev_id) {
array_push($desired_arr[$prev_key][$value['id']], $value['content']);
} else {
$desired_arr[$key][$value['id']] = (array)$value['content'];
$prev_key = $key;
}
$prev_id = $this_id;
}
$desired_arr = array_values($desired_arr);
I have the following stdClass Object contained within $response:
stdClass Object ( [domain] => stdClass Object ( [id] => d1111111 [spamscore] => 75 [rejectscore] => 200 ) [domainalias] => Array ( ) [wildcard] => Array ( ) [catchall] => Array ( ) [forward] => Array ( ) [mailbox] => Array (
[0] => stdClass Object ( [highEmailNotification] => [id] => m1111111 [lastPasswordChange] => 2020-02-19T22:41:12+00:00 [local] => mailbox1 [lowEmailNotification] => [quotaMB] => 10240 [receive] => 1 [rejectscore] => [send] => 1 [spamscore] => [usageMB] => 0 [enabled] => 1 )
[1] => stdClass Object ( [highEmailNotification] => [id] => m2222222 [lastPasswordChange] => 2020-02-17T15:46:21+00:00 [local] => mailbox2 [lowEmailNotification] => [quotaMB] => 10240 [receive] => 1 [rejectscore] => [send] => 1 [spamscore] => [usageMB] => 0 [enabled] => 1 )
[2] => stdClass Object ( [highEmailNotification] => [id] => m3333333 [lastPasswordChange] => 2020-02-19T15:00:36+00:00 [local] => mailbox3 [lowEmailNotification] => [quotaMB] => 1024 [receive] => 1 [rejectscore] => 0 [send] => 1 [spamscore] => 75 [usageMB] => 0 [enabled] => 1 ) ) [spamblacklist] => Array ( ) [spamwhitelist] => Array ( ) [responder] => Array ( ) [name] => domain.com )
I need to convert it into an array and extract particular values, i.e. [id] and [local] from it.
Speed is also an issue, as this array will grow to thousands of items, so if there is other, quicker way than 'foreach' it would be better.
I used some suggestions from here, such as:
$array = json_decode(json_encode($response), True);
foreach ($array as $var)
{
echo $var['id'] . ' - ' . $var['local'] . "<br>";
}
and got partial success with the results:
d1111111 -
-
-
-
-
i - i
(so it found the very first [id] value)
it however missed the most important values I am after.
What I need to get is:
m1111111 - mailbox1
m2222222 - mailbox2
m3333333 - mailbox3
Any suggestions are greatly appreciated.
The values you're trying to print is in a nested array within $response.
Try this.
$array = json_decode(json_encode($response['mailbox']), True);
foreach ($array as $var)
{
echo $var['id'] . ' - ' . $var['local'] . "<br>";
}
i have two arrays and i want two merge using the same value within each array..
the first array is :
[0] => Array
(
[id] => 1
[uid] => 0090000157
[cid] => 0090000007
[extension] => 202
[secret] => Myojyo42f!
[leader] => 1
[simultaneous] =>
[confbridge_id] => 2
[created_at] => 2015-07-26 12:20:20
[updated_at] => 2015-07-26 12:20:20
)
[1] => Array
(
[id] => 2
[uid] => 0090000159
[cid] => 0090000007
[extension] =>
[secret] => Myojyo42f!
[leader] =>
[simultaneous] =>
[confbridge_id] => 2
[created_at] => 2015-07-26 14:23:41
[updated_at] => 2015-07-26 14:23:41
)
)
and the second array is:
Array
(
[0] => Array
(
[_id] => 55b52f4c2bab38fc63b6272a
[event] => ConfbridgeJoin
[channel] => SIP/peer_voip301confbridge-0000001b
[uniqueid] => 1437937478.63
[conference] => 0090000156
[calleridnum] => 0090000157
[calleridname] => 0090000157
[__v] => 0
[sipSetting] => Array
(
[accountcode] =>
[accountcode_naisen] => 202
[extentype] => 0
[extenrealname] =>
[name] => 0090000157
[secret] => Myojyo42f!
[username] => 0090000157
[context] => innercall_xdigit
[gid] => 101
[cid] => 0090000007
)
)
[1] => Array
(
[_id] => 55b53a2e2bab38fc63b6272b
[event] => ConfbridgeJoin
[channel] => SIP/peer_voip301confbridge-0000001c
[uniqueid] => 1437940260.66
[conference] => 0090000156
[calleridnum] => 0090000158
[calleridname] => UID2
[__v] => 0
[sipSetting] => Array
(
[accountcode] =>
[accountcode_naisen] => 203
[extentype] => 0
[extenrealname] =>
[name] => 0090000158
[secret] => Myojyo42f!
[username] => 0090000158
[context] => innercall_xdigit
[gid] => 101
[cid] => 0090000007
)
)
)
i want to merge array with the same value for example :
first array has = [uid] => 0090000157
second array has = [calleridnum] => 0090000157
is it possible to merge them?
this is my code
{foreach from=$participants item=participant key=p }
{foreach from=$conference_participants item=conference_participant key=c}
{if$participants.calleridnum == $conference_participants.uid}
//how to get data here ?
{/if}
{/foreach}
{/foreach}
Could this be what you're looking for?
Sorry for all the changes, I should have tested it... grr
(I've put this in PHPFiddle:
<pre>
<?php
$participants = [
[ 'calleridnum' => 1,
'test' => 'yay'
]
];
$conferance_participants = [
[ 'uid' => 1,
'test' => 'yay2',
'dit' => 'deze'
]
];
foreach ($participants as $participant=>$p) {
foreach ($conferance_participants as $conferance_participant=>$c) {
if ($p['calleridnum'] == $c['uid']) {
// ID's match do the magic here
foreach ( $c as $key=>$val ) {
if (!isset($p[$key])) {
// Value is new, copy the conferance_participant to the participant
$participants[$participant][$key] = $val;
}
} // Merging data
} // If: Match
}
}
print_r( $participants );
?>
)
I am trying to use the Salesforce Analytics api to get a report filtered by date, but when I apply the date filters it does not seem to stick, only the default filter applies.
Here is the POST data that I am sending
{
"reportMetadata": {
"aggregates": [
"FORMULA1",
"FORMULA2",
"FORMULA3",
"RowCount"
],
"currency": null,
"detailColumns": [
"SUBJECT",
"DUE_DATE",
"PRIORITY",
"STATUS",
"TASK",
"ACCOUNT",
"CONTACT",
"LEAD",
"OPPORTUNITY"
],
"developerName": "me",
"groupingsAcross": [
{
"dateGranularity": "None",
"name": "CALLDISPOSITION",
"sortAggregate": null,
"sortOrder": "Asc"
}
],
"groupingsDown": [
{
"dateGranularity": "None",
"name": "ASSIGNED",
"sortAggregate": null,
"sortOrder": "Asc"
}
],
"historicalSnapshotDates": [],
"id": "00OC0000006nlWpMAI",
"name": "report",
"reportBooleanFilter": "1 AND 2 AND 3",
"reportFilters": [
{
"column": "CALLTYPE",
"operator": "equals",
"value": "Outbound"
},
{
"value": "2014-08-01",
"column": "Activity.qbdialer__Call_Date_Time__c",
"operator": "greaterOrEqual"
},
{
"value": "2014-08-31",
"column": "Activity.qbdialer__Call_Date_Time__c",
"operator": "lessOrEqual"
}
],
"reportFormat": "MATRIX",
"reportType": {
"label": "Tasks and Events",
"type": "Activity"
}
}
}
and here is what I get back
Array
(
[status] => Array
(
[http_code] => 200
)
[contents] => Array
(
[attributes] => Array
(
[completionDate] => 2014-08-19T17:23:26Z
[id] => 0LGC00000024PlIOAU
[ownerId] => 005C0000003KHKbIAO
[reportId] => 00OC0000006nlWpMAI
[reportName] => report
[requestDate] => 2014-08-19T17:23:25Z
[status] => Success
[type] => ReportInstance
)
[allData] => 1
[factMap] => Array
(
[T!2] => Array
(
[aggregates] => Array
(
[0] =>
[1] => Array
(
[label] => 6.67%
[value] => 6.66666667
)
[2] =>
[3] => Array
(
[label] => 1
[value] => 1
)
)
)
[T!T] => Array
(
[aggregates] => Array
(
[0] =>
[1] =>
[2] =>
[3] => Array
(
[label] => 15
[value] => 15
)
)
)
[T!1] => Array
(
[aggregates] => Array
(
[0] =>
[1] => Array
(
[label] => 13.33%
[value] => 13.33333333
)
[2] =>
[3] => Array
(
[label] => 2
[value] => 2
)
)
)
[0!0] => Array
(
[aggregates] => Array
(
[0] => Array
(
[label] => 3.00
[value] => 3
)
[1] =>
[2] => Array
(
[label] => 0.25
[value] => 0.25
)
[3] => Array
(
[label] => 12
[value] => 12
)
)
)
[0!T] => Array
(
[aggregates] => Array
(
[0] =>
[1] =>
[2] =>
[3] => Array
(
[label] => 15
[value] => 15
)
)
)
[T!0] => Array
(
[aggregates] => Array
(
[0] =>
[1] => Array
(
[label] => 80.00%
[value] => 80
)
[2] =>
[3] => Array
(
[label] => 12
[value] => 12
)
)
)
[0!2] => Array
(
[aggregates] => Array
(
[0] => Array
(
[label] => 0.00
[value] => 0
)
[1] =>
[2] => Array
(
[label] => 0.00
[value] => 0
)
[3] => Array
(
[label] => 1
[value] => 1
)
)
)
[0!1] => Array
(
[aggregates] => Array
(
[0] => Array
(
[label] => 1.00
[value] => 1
)
[1] =>
[2] => Array
(
[label] => 0.50
[value] => 0.5
)
[3] => Array
(
[label] => 2
[value] => 2
)
)
)
)
[groupingsAcross] => Array
(
[groupings] => Array
(
[0] => Array
(
[groupings] => Array
(
)
[key] => 0
[label] => -
[value] =>
)
[1] => Array
(
[groupings] => Array
(
)
[key] => 1
[label] => Contact
[value] => Contact
)
[2] => Array
(
[groupings] => Array
(
)
[key] => 2
[label] => Correct Contact
[value] => Correct Contact
)
)
)
[groupingsDown] => Array
(
[groupings] => Array
(
[0] => Array
(
[groupings] => Array
(
)
[key] => 0
[label] => first sftest1
[value] => 005C0000003KHKbIAO
)
)
)
[hasDetailRows] =>
[reportExtendedMetadata] => Array
(
[aggregateColumnInfo] => Array
(
[RowCount] => Array
(
[acrossGroupingContext] =>
[dataType] => int
[downGroupingContext] =>
[label] => Record Count
)
[FORMULA1] => Array
(
[acrossGroupingContext] => CALLDISPOSITION
[dataType] => double
[downGroupingContext] => ASSIGNED
[label] => Ring Time
)
[FORMULA3] => Array
(
[acrossGroupingContext] => CALLDISPOSITION
[dataType] => double
[downGroupingContext] => ASSIGNED
[label] => Average Ring Time
)
[FORMULA2] => Array
(
[acrossGroupingContext] => CALLDISPOSITION
[dataType] => percent
[downGroupingContext] => GRAND_SUMMARY
[label] => Group Average
)
)
[detailColumnInfo] => Array
(
[SUBJECT] => Array
(
[dataType] => string
[label] => Subject
)
[DUE_DATE] => Array
(
[dataType] => date
[label] => Date
)
[PRIORITY] => Array
(
[dataType] => picklist
[label] => Priority
)
[STATUS] => Array
(
[dataType] => picklist
[label] => Status
)
[TASK] => Array
(
[dataType] => boolean
[label] => Task
)
[ACCOUNT] => Array
(
[dataType] => string
[label] => Company / Account
)
[CONTACT] => Array
(
[dataType] => string
[label] => Contact
)
[LEAD] => Array
(
[dataType] => string
[label] => Lead
)
[OPPORTUNITY] => Array
(
[dataType] => string
[label] => Opportunity
)
)
[groupingColumnInfo] => Array
(
[ASSIGNED] => Array
(
[dataType] => string
[groupingLevel] => 0
[label] => Assigned
)
[CALLDISPOSITION] => Array
(
[dataType] => string
[groupingLevel] => 0
[label] => Call Result
)
)
)
[reportMetadata] => Array
(
[aggregates] => Array
(
[0] => FORMULA1
[1] => FORMULA2
[2] => FORMULA3
[3] => RowCount
)
[currency] =>
[detailColumns] => Array
(
[0] => SUBJECT
[1] => DUE_DATE
[2] => PRIORITY
[3] => STATUS
[4] => TASK
[5] => ACCOUNT
[6] => CONTACT
[7] => LEAD
[8] => OPPORTUNITY
)
[developerName] => Ring_Time_By_Agent
[groupingsAcross] => Array
(
[0] => Array
(
[dateGranularity] => None
[name] => CALLDISPOSITION
[sortAggregate] =>
[sortOrder] => Asc
)
)
[groupingsDown] => Array
(
[0] => Array
(
[dateGranularity] => None
[name] => ASSIGNED
[sortAggregate] =>
[sortOrder] => Asc
)
)
[historicalSnapshotDates] => Array
(
)
[id] => 00OC0000006nlWpMAI
[name] => report
[reportBooleanFilter] =>
[reportFilters] => Array
(
[0] => Array
(
[column] => CALLTYPE
[operator] => equals
[value] => Outbound
)
)
[reportFormat] => MATRIX
[reportType] => Array
(
[label] => Tasks and Events
[type] => Activity
)
)
)
)
As you can see in the results only the CALLTYPE column filter applied (this is the default filter).
Does anyone see anything wrong with the POST data that I am sending?
I have tried using other reports and other date columns to filter on, but it is always the same, only the default filters apply.
I found the answer. I was not setting the header Content-type to application/json. Once I did that the filters started working.
I have 2 arrays. 1 fetching from database and other one is from view page. I am developing a online test exam website so i have to check if the answer entered by user is correct or not.Here is the 1st one.
Array
(
[0] => Array
(
[Question] => Array
(
[id] => 51f92e34-c5a8-4de3-b264-0ff0d0483c4c
[aptitude_id] => 51f92441-d510-4c3d-85e3-0ff0d0483c4c
[paper_id] => 51f924cc-a158-441e-9119-0ff0d0483c4c
[qus] => What is ur name?
[slug] => name-find
[image] =>
[opt1] => x
[opt2] => y
[opt3] => a
[opt4] => b
[opt5] => c
[answer_id] => 4
[description] =>
[ansimage] =>
)
[Aptitude] => Array
(
[id] => 51f92441-d510-4c3d-85e3-0ff0d0483c4c
[name] => php
[slug] => php
)
[Paper] => Array
(
[id] => 51f924cc-a158-441e-9119-0ff0d0483c4c
[aptitude_id] => 51f92441-d510-4c3d-85e3-0ff0d0483c4c
[name] => aptitude1
[slug] => aptitude1
)
[Answer] => Array
(
[id] => 4
[name] => D
)
)
[1] => Array
(
[Question] => Array
(
[id] => 51fe4098-c344-4790-9e46-0fb4d0483c4c
[aptitude_id] => 51f92441-d510-4c3d-85e3-0ff0d0483c4c
[paper_id] => 51f924cc-a158-441e-9119-0ff0d0483c4c
[qus] => Place?
[slug] => place
[image] =>
[opt1] => ss
[opt2] => sss
[opt3] => ss
[opt4] => ss
[opt5] => ss
[answer_id] => 3
[description] =>
[ansimage] =>
)
[Aptitude] => Array
(
[id] => 51f92441-d510-4c3d-85e3-0ff0d0483c4c
[name] => php
[slug] => php
)
[Paper] => Array
(
[id] => 51f924cc-a158-441e-9119-0ff0d0483c4c
[aptitude_id] => 51f92441-d510-4c3d-85e3-0ff0d0483c4c
[name] => aptitude1
[slug] => aptitude1
)
[Answer] => Array
(
[id] => 3
[name] => C
)
)
[2] => Array
(
[Question] => Array
(
[id] => 51fe40ad-9ddc-4f07-94dc-0fb4d0483c4c
[aptitude_id] => 51f92441-d510-4c3d-85e3-0ff0d0483c4c
[paper_id] => 51f924cc-a158-441e-9119-0ff0d0483c4c
[qus] => hayywep?
[slug] => dada
[image] =>
[opt1] => a
[opt2] => a
[opt3] => a
[opt4] => a
[opt5] => a
[answer_id] => 3
[description] =>
[ansimage] =>
)
[Aptitude] => Array
(
[id] => 51f92441-d510-4c3d-85e3-0ff0d0483c4c
[name] => php
[slug] => php
)
[Paper] => Array
(
[id] => 51f924cc-a158-441e-9119-0ff0d0483c4c
[aptitude_id] => 51f92441-d510-4c3d-85e3-0ff0d0483c4c
[name] => aptitude1
[slug] => aptitude1
)
[Answer] => Array
(
[id] => 3
[name] => C
)
)
)
and
Array
(
[51f92e34-c5a8-4de3-b264-0ff0d0483c4c] => 3
[51fe4098-c344-4790-9e46-0fb4d0483c4c] => 3
[51fe40ad-9ddc-4f07-94dc-0fb4d0483c4c] => 3
)
i wrote this code
foreach($res as $res1):
foreach($ans as $ans1):
if($res1['Question']['answer_id']==$ans1)
{
print_r($res1['Question']['id']);
}
endforeach;
endforeach;
Output:
51f92e34-c5a8-4de3-b264-0ff0d0483c4c
51f92e34-c5a8-4de3-b264-0ff0d0483c4c
51f92e34-c5a8-4de3-b264-0ff0d0483c4c
51fe4098-c344-4790-9e46-0fb4d0483c4c
51fe4098-c344-4790-9e46-0fb4d0483c4c
51fe4098-c344-4790-9e46-0fb4d0483c4c
51fe40ad-9ddc-4f07-94dc-0fb4d0483c4c
51fe40ad-9ddc-4f07-94dc-0fb4d0483c4c
51fe40ad-9ddc-4f07-94dc-0fb4d0483c4c
how to remove the duplication?
Try array_unique
$_results = array();
foreach($res as $res1):
foreach($ans as $ans1):
if($res1['Question']['answer_id']==$ans1)
{
$_results[] = $res1['Question']['id'];
}
endforeach;
endforeach;
$results = array_unique($_results);
pr($results);