How to get the value form SimpleSAML_Session Object - php

The saml Session is SimpleSAML_Session Object
$data =
(
[trackid:SimpleSAML_Session:private] => 3eb
[idp:SimpleSAML_Session:private] => https://abs.com
[authenticated:SimpleSAML_Session:private] => 1
[attributes:SimpleSAML_Session:private] => Array
(
[firstName] => Array
(
[0] => Aravind
)
[lastName] => Array
(
[0] => M
)
[email] => Array
(
[0] => aravind.muthu#abc.com
)
)
Here i need to take email value . How do i have parse the SAMLobj.
Thanks in advance

Using the below code we can get the values from SAML object.
$values = $data->getAttributes();
Now $values contains an array values .
For more info goto http://simplesamlphp.org/docs/1.6/simplesamlphp-sp-api
Thanks

Related

how to push value , spesific by index in php?

i have data array of objec . in this :
Array
(
[0] => Array
(
[name] => Soil
[method] =>
)
[1] => Array
(
[name] => 10 mm
[method] =>
)
)
here I receive input index , and value ..
$index = 1;
$method = 'junior'
I want to push the data based on the index data I received
result
Array
(
[0] => Array
(
[name] => Soil
[method] =>
)
[1] => Array
(
[nama_barang] => 10 mm
[method] => junior // push by index 1
)
)
How to ? thanks
$yourArray[1]['method'] = 'junior'
In PHP, you just assign the value to the array. The path keys are automatically created if they do not exist.

How to Fetch data from Array in WordPress

Array
(
[0] => stdClass Object
(
[meta_id] => 23233
[post_id] => 4467
[meta_key] => first_name
[meta_value] => Daud
)
)
How can I echo post_id from this array for all posts using while or foreach statement?
Array
(
[classic-editor-remember] => Array
(
[0] => classic-editor
)
[_edit_lock] => Array
(
[0] => 1582905950:5
)
[_edit_last] => Array
(
[0] => 5
)
[_thumbnail_id] => Array
(
[0] => 4376
)
[slide_template] => Array
(
[0] => default
)
[_yoast_wpseo_content_score] => Array
(
[0] => 30
)
[_yoast_wpseo_primary_advisor_category] => Array
(
[0] =>
)
[title] => Array
(
[0] => Demo Daniel Wrenne, CFP, ChFC
)
[designation] => Array
(
[0] => Wrenne Financial Planing, LLC Lexington, KY
)
[client_specialities] => Array
(
[0] => Gen Y/Millennials, Medical Professionals
)
[address] => Array
(
[0] => 3223 S LEHI DR
)
[phone_number] => Array
(
[0] => 64646446486
)
[email_address] => Array
(
[0] => demo#demo.com
)
[website_url] => Array
(
[0] => a:3:{s:3:"url";s:23:"https://www.google.com/";s:4:"text";s:20:"View Advisor Profile";s:6:"target";s:4:"none";}
)
[first_name] => Array
(
[0] => Daud
)
[last_name] => Array
(
[0] => Yahya
)
)
And how can I get las_name, first_name, email, address, website url, specialities, designation and title from the above array using and loop like while or foreach loop.
This is less a WordPress question and a basic PHP foreach question.
The first example you have is an Object, so you need to access the properties, e.g. meta_id, post_id like:
// THIS IS JUST AN EXAMPLE. YOUR VARIABLE WILL CHANGE BASED ON HOW YOU GOT THE DATA. `$object_array` is how you got the data to begin with.
foreach( $object_array as $object ) {
$post_id = $object->post_id;
echo $post_id;
}
For your second example, since there is only one array key inside each array key, you would set it up like this:
// Example. you would use whatever you used to get the array to begin with as the `$array`.
foreach ($array as $item ) {
$last_name = $item['last_name'][0];
$first_name = $item['first_name'][0];
....
}

Manipulation or modification of array

I'm new to PHP. I'm doing one my project with php and I'm new to array functions and all those things. I have tried but not get success in that. let me show you my sql query array.
I have one my array which is as below:
Array
(
[0] => Array
(
[pc_eventDate] => 2016-08-25
[ufname] => Rutul
[ulname] => Shah
[name] => Clinic
)
[1] => Array
(
[pc_eventDate] => 2016-08-26
[ufname] => Rutul
[ulname] => Shah
[name] => Clinic
)
[2] => Array
(
[pc_eventDate] => 2016-08-25
[ufname] => Administrator
[ulname] => Administrator
[name] => Clinic
)
[3] => Array
(
[pc_eventDate] => 2016-08-26
[ufname] => Administrator
[ulname] => Administrator
[name] => Clinic
)
[4] => Array
(
[pc_eventDate] => 2016-08-25
[ufname] => Administrator
[ulname] => Administrator
[name] => Clinic
)
[5] => Array
(
[pc_eventDate] => 2016-08-26
[ufname] => Amit
[ulname] => Mahida
[name] => Cancer Specialist
)
[6] => Array
(
[pc_eventDate] => 2016-08-26
[ufname] => Amit
[ulname] => Mahida
[name] => Breach Candy Hospital
)
)
Now I want my resulted array as below :
Array
(
[2016-08-25] => Array
(
[ Clinic] => Array
(
[Rutul Shah] => Array
(
[appointments] => 1
)
[Administrator Administrator] => Array
(
[appointments] => 2
)
)
)
[2016-08-26] => Array
(
[Clinic] => Array
(
[Rutul Shah] => Array
(
[appointments] => 1
)
[Administrator Administrator] => Array
(
[appointments] => 1
)
)
[Cancer Specialist] => Array
(
[Amit Mahida] => Array
(
[appointments] => 1
)
)
[Breach Candy Hospital] => Array
(
[Amit Mahida] => Array
(
[appointments] => 1
)
)
)
)
you want to loop through your appointments array and use its contents to generate the other data structure. let's call your first array $input and your second array $output:
// initialize output array
$output = [];
// loop through each $appt in the $input array
foreach($input as $appt) {
// get shorter var names for appt data
$date = $appt['pc_eventDate'];
$name = $appt['name'];
$uname = $appt['ufname'].' '.$appt['ulname'];
// initialize each level of the data structure if it doesn't already exist
if(!isset($output[$date])) $output[$date] = [];
if(!isset($output[$date][$name])) $output[$date][$name] = [];
if(!isset($output[$date][$name][$uname])) $output[$date][$name][$uname] = [];
// initialize the number of appts to 0
if(!isset($output[$date][$name][$uname]['appointments'])) $output[$date][$name][$uname]['appointments'] = 0;
// increment the number of appts
$output[$date][$name][$uname]['appointments']++;
}
the important thing is the intialization of each sub-array in the new structure according to the data in the old structure -- from there we're just counting the number of appointments that match the new data.
good luck!
Say the array is question is $arr
This will arrange the array in the way you wanted as solution
foreach ($arr as $key => $value) {
if(!is_array($value['pc_eventDate]))
$value['pc_eventDate] = [];
if(!is_array($value['pc_eventDate]['name']))
$value['pc_eventDate]['name'] = [];
if(!is_array($value['pc_eventDate']['name']['ufname'.' ulname'])){
$value['pc_eventDate']['name']['ufname'.' ulname'] = [];
$value['pc_eventDate']['name']['ufname'.' ulname']['appointments'] = 1;
}else{
$value['pc_eventDate']['name']['ufname'.' ulname']['appointments'] += 1;
}
}
You need to do something like the above.
Try running the above code, there could be some typo. If its doesnt yields your desired result, try commenting out all the lines in the body of the foreach and var_dump() each step to test the building of the array structure.
Thanks

cakephp find all data format

I am using following to find data.
$records = $this->ModelName->find('all', array('fields' => array('name','email')));
It gives me data in following format.
Array
(
[0] => Array
(
[ModelName] => Array
(
[name] => val
[email] => value1
)
)
[1] => Array
(
[ModelName] => Array
(
[name] => val
[email] => value1
)
)
)
Can I get the data in following format? If yes, how? I need following format of data array.
Array
(
[0] => Array
(
[name] => val
[email] => value1
)
[1] => Array
(
[name] => val
[email] => value1
)
)
This will do
$new_array = Set::classicExtract($records, '{n}.ModelName');
foreach ($records as $i => $record) {
$records[$i] = $record['ModelName'];
}

Strip a IPTC.php result into two variables

I have the following code:
<?php
require_once('IPTC.php');
$iptc = new Image_IPTC('001.jpg');
print_r($iptc);
?>
And it returns:
Image_IPTC Object ( [_sFilename] => 001.jpg [_aIPTC] => Array (
[1#090] => Array ( [0] => %G ) [2#000] => Array ( [0] => ) [2#005]
=> Array ( [0] => TITULO NO WINDOWS, TITLE NO BRIDGE ) [2#080] => Array ( [0] => pictureauthor ) [2#085] => Array ( [0] => photographer )
[2#090] => Array ( [0] => mycity ) [2#095] => Array ( [0] => ST )
[2#101] => Array ( [0] => mycountry ) [2#105] => Array ( [0] =>
IWANTTHIS1 ) [2#116] => Array ( [0] => copyrightinfo ) [2#120] => Array ( [0] => IWANTTHIS2 ) ) [_bIPTCParse] => 1
)
This is a dummy question, but how do I put texts "IWANTTHIS1" and "IWANTTHIS2" into 2 different variables to use like this:
echo "title: $variable1 <br />";
echo "descr: $variable2";
Resulting in:
title: IWANTTHIS1
descr: IWANTTHIS2
I'm pretty shure it's extremelly easy for you guys, but I'm still learning all this. I think it's an array inside an array? Can't figure it out.
Thanks.
$variable1 = $iptc->_aIPTC['2#105'][0];
$variable2 = $iptc->_aIPTC['2#120'][0];
Rodaine's answer was giving me "Fatal error: Cannot use object of type Image_IPTC as array". With some research, the final correct answer is:
$variable1 = $iptc->_aIPTC['2#105'][0];
$variable2 = $iptc->_aIPTC['2#120'][0];
I wouldn't be able to achieve it by myself at all, therefore I'm marking Rodaine's answer as correct.
Thank you very much.

Categories