Extracting data from this object/array? How to do it - php

Here is a snippet of the print off of $wp_scripts
WP_Scripts Object
(
[base_url] => http://*****
[content_url] => http://*****
[default_version] => 3.5.1
[in_footer] => Array
(
)
[concat] =>
[concat_version] =>
[do_concat] =>
[print_html] =>
[print_code] =>
[ext_handles] =>
[ext_version] =>
[default_dirs] => Array
(
[0] => /wp-admin/js/
[1] => /wp-includes/js/
)
[registered] => Array
(
[utils] => _WP_Dependency Object
(
[handle] => utils
[src] => /wp-includes/js/utils.min.js
[deps] => Array
(
)
How would i Extract some data, for example "/wp-includes/js/utils.min.js"??
Thanks

$wp_scripts->registered['utils']->src
Accessing object properties via ->
Accessing array elements via [/* String or integer here*/]

$object = new WP_Scripts;
$src = $object->registered['utils']->src;

Related

How to get the value from a specific key in an array?

I have the following array:
Array (
[result] => Array (
[id] => 58fba3ebf4
[type] => A
[name] => ser.domain.com
[content] => 192.168.100.1
[proxiable] =>
[proxied] =>
[ttl] => 1
[priority] => 10
[locked] =>
[zone_id] => eb0d86828e3ac837c
[zone_name] => domain.com
[modified_on] => 2018-07-06T06:37:14.069598Z
[created_on] => 2018-07-06T06:37:14.069598Z
[meta] => Array (
[auto_added] =>
[managed_by_apps] =>
[managed_by_argo_tunnel] =>
)
)
[success] => 1
[errors] => Array ( )
[messages] => Array ( )
)
How can I just get the value from id?
$data =json_decode($response);
$id = $data->result->id;
Assuming your payload from the request was $response.
You already have a multi-dimensional array so just try like this
echo $arrays['result']['id']; // this will return id
echo $arrays['result']['type']; // this will return type
Here is solution
// $result_array() is your reponse from curl PHP
$data = $result_array();
$id = $data['result']['id'];

php-xapi/client parse getStatements method object

I am using php-xapi/client library to get all the statements stored in LRS.
Code:
$results = $statementsApiClient->getStatements();
Document link:
https://github.com/php-xapi/client/blob/master/doc/statements.md
It returns the StatementResult object. But I'm not able to access it's private properties. Nothing is mentioned in their document.
Below is the output:
Xabbuh\XApi\Model\StatementResult Object
(
[statements:Xabbuh\XApi\Model\StatementResult:private] => Array
(
[0] => Xabbuh\XApi\Model\Statement Object
(
[id:Xabbuh\XApi\Model\Statement:private] => Xabbuh\XApi\Model\StatementId Object
(
[uuid:Xabbuh\XApi\Model\StatementId:private] => Rhumsaa\Uuid\Uuid Object
(
[fields:protected] => Array
(
[time_low] => e994a27f
[time_mid] => cbfe
[time_hi_and_version] => 4272
[clock_seq_hi_and_reserved] => bf
[clock_seq_low] => d7
[node] => 147d334723b3
)
)
)
[verb:Xabbuh\XApi\Model\Statement:private] => Xabbuh\XApi\Model\Verb Object
(
[id:Xabbuh\XApi\Model\Verb:private] => Xabbuh\XApi\Model\IRI Object
(
[value:Xabbuh\XApi\Model\IRI:private] => http://adlnet.gov/expapi/verbs/experienced
)
[display:Xabbuh\XApi\Model\Verb:private] => Xabbuh\XApi\Model\LanguageMap Object
(
[map:Xabbuh\XApi\Model\LanguageMap:private] => Array
(
[en-US] => experienced
)
)
)
[actor:Xabbuh\XApi\Model\Statement:private] => Xabbuh\XApi\Model\Agent Object
(
[iri:Xabbuh\XApi\Model\Actor:private] => Xabbuh\XApi\Model\InverseFunctionalIdentifier Object
(
[mbox:Xabbuh\XApi\Model\InverseFunctionalIdentifier:private] => Xabbuh\XApi\Model\IRI Object
(
[value:Xabbuh\XApi\Model\IRI:private] => mailto:cwaghmare#xento.com
)
[mboxSha1Sum:Xabbuh\XApi\Model\InverseFunctionalIdentifier:private] =>
[openId:Xabbuh\XApi\Model\InverseFunctionalIdentifier:private] =>
[account:Xabbuh\XApi\Model\InverseFunctionalIdentifier:private] =>
)
[name:Xabbuh\XApi\Model\Actor:private] => Chinmay
)
[object:Xabbuh\XApi\Model\Statement:private] => Xabbuh\XApi\Model\Activity Object
(
[id:Xabbuh\XApi\Model\Activity:private] => Xabbuh\XApi\Model\IRI Object
(
[value:Xabbuh\XApi\Model\IRI:private] => http:///68DFljpCPci
)
[definition:Xabbuh\XApi\Model\Activity:private] => Xabbuh\XApi\Model\Definition Object
(
[name:Xabbuh\XApi\Model\Definition:private] => Xabbuh\XApi\Model\LanguageMap Object
(
[map:Xabbuh\XApi\Model\LanguageMap:private] => Array
(
[und] => Video Slide 1
)
)
[description:Xabbuh\XApi\Model\Definition:private] => Xabbuh\XApi\Model\LanguageMap Object
(
[map:Xabbuh\XApi\Model\LanguageMap:private] => Array
(
[und] => Video Slide 1
)
)
[type:Xabbuh\XApi\Model\Definition:private] => Xabbuh\XApi\Model\IRI Object
(
[value:Xabbuh\XApi\Model\IRI:private] => http://adlnet.gov/expapi/activities/module
)
[moreInfo:Xabbuh\XApi\Model\Definition:private] =>
[extensions:Xabbuh\XApi\Model\Definition:private] =>
)
)
[result:Xabbuh\XApi\Model\Statement:private] =>
[authority:Xabbuh\XApi\Model\Statement:private] => Xabbuh\XApi\Model\Agent Object
(
[iri:Xabbuh\XApi\Model\Actor:private] => Xabbuh\XApi\Model\InverseFunctionalIdentifier Object
(
[mbox:Xabbuh\XApi\Model\InverseFunctionalIdentifier:private] => Xabbuh\XApi\Model\IRI Object
(
[value:Xabbuh\XApi\Model\IRI:private] => mailto:hello#learninglocker.net
)
[mboxSha1Sum:Xabbuh\XApi\Model\InverseFunctionalIdentifier:private] =>
[openId:Xabbuh\XApi\Model\InverseFunctionalIdentifier:private] =>
[account:Xabbuh\XApi\Model\InverseFunctionalIdentifier:private] =>
)
[name:Xabbuh\XApi\Model\Actor:private] => New Client
)
[created:Xabbuh\XApi\Model\Statement:private] => DateTime Object
(
[date] => 2018-04-11 06:46:15.231000
[timezone_type] => 2
[timezone] => Z
)
[stored:Xabbuh\XApi\Model\Statement:private] => DateTime Object
(
[date] => 2018-04-11 06:46:14.746000
[timezone_type] => 2
[timezone] => Z
)
[context:Xabbuh\XApi\Model\Statement:private] => Xabbuh\XApi\Model\Context Object
(
[registration:Xabbuh\XApi\Model\Context:private] =>
[instructor:Xabbuh\XApi\Model\Context:private] =>
[team:Xabbuh\XApi\Model\Context:private] =>
[contextActivities:Xabbuh\XApi\Model\Context:private] => Xabbuh\XApi\Model\ContextActivities Object
(
[parentActivities:Xabbuh\XApi\Model\ContextActivities:private] => Array
(
[0] => Xabbuh\XApi\Model\Activity Object
(
[id:Xabbuh\XApi\Model\Activity:private] => Xabbuh\XApi\Model\IRI Object
(
[value:Xabbuh\XApi\Model\IRI:private] => http://
)
[definition:Xabbuh\XApi\Model\Activity:private] =>
)
)
[groupingActivities:Xabbuh\XApi\Model\ContextActivities:private] => Array
(
[0] => Xabbuh\XApi\Model\Activity Object
(
[id:Xabbuh\XApi\Model\Activity:private] => Xabbuh\XApi\Model\IRI Object
(
[value:Xabbuh\XApi\Model\IRI:private] => http://
)
[definition:Xabbuh\XApi\Model\Activity:private] =>
)
)
[categoryActivities:Xabbuh\XApi\Model\ContextActivities:private] =>
[otherActivities:Xabbuh\XApi\Model\ContextActivities:private] =>
)
[revision:Xabbuh\XApi\Model\Context:private] =>
[platform:Xabbuh\XApi\Model\Context:private] =>
[language:Xabbuh\XApi\Model\Context:private] =>
[statement:Xabbuh\XApi\Model\Context:private] =>
[extensions:Xabbuh\XApi\Model\Context:private] =>
)
[attachments:Xabbuh\XApi\Model\Statement:private] =>
)
)
[moreUrlPath:Xabbuh\XApi\Model\StatementResult:private] => Xabbuh\XApi\Model\IRL Object
(
[value:Xabbuh\XApi\Model\IRL:private] =>
)
)
How can I access Id, Actor and Verb properties of the above StatementResult Object?
Any help would be highy appreciated.
The StatementResult object does not contain those properties, it contains a list of statements where each of those objects will then contain those properties. You would need to call $statements = $results->getStatements(); to retrieve an array of the Statement objects, then access those properties (id, actor, etc.) via the Statement class interface. The individual model classes are defined in a separate repo, see https://github.com/php-xapi/model/tree/master/src.

Converting an nested xAPI JSON output into PHP Array

Array
(
[0] => TinCan\Statement Object
(
[id:protected] => 0a53e06c-64a7-4902-930e-993bb228cd49
[stored:protected] => 2018-02-24T04:21:22.456Z
[authority:protected] => TinCan\Agent Object
(
[objectType:protected] => Agent
[name:protected] => sabarish
[mbox:protected] =>
[mbox_sha1sum:protected] =>
[openid:protected] =>
[account:protected] => TinCan\AgentAccount Object
(
[name:protected] => 248a06f20aa62f
[homePage:protected] => https://sandbox.watershedlrs.com
)
)
[version:protected] => 1.0.0
[attachments:protected] => Array
(
)
[actor:protected] => TinCan\Agent Object
(
[objectType:protected] => Agent
[name:protected] => Akshaya Manikandan
[mbox:protected] => mailto:aksh.m14#gmail.com
[mbox_sha1sum:protected] =>
[openid:protected] =>
[account:protected] =>
)
[verb:protected] => TinCan\Verb Object
(
[id:protected] => http://adlnet.gov/expapi/verbs/skipped
[display:protected] => TinCan\LanguageMap Object
(
[_map:protected] => Array
(
[en] => skipped
)
)
)
[target:protected] => TinCan\Activity Object
(
[objectType:TinCan\Activity:private] => Activity
[id:protected] => https://app.acuizen.com/populate_form/965/1573/4690
[definition:protected] =>
)
[result:protected] =>
[context:protected] => TinCan\Context Object
(
[registration:protected] =>
[instructor:protected] =>
[team:protected] =>
[contextActivities:protected] => TinCan\ContextActivities Object
(
[category:protected] => Array
(
[0] => TinCan\Activity Object
(
[objectType:TinCan\Activity:private] => Activity
[id:protected] => http://acuizen.com/ActivitySkipped
[definition:protected] => TinCan\ActivityDefinition Object
(
[type:protected] => http://id.tincanapi.com/activitytype/Assignment
[name:protected] => TinCan\LanguageMap Object
(
[_map:protected] => Array
(
)
)
[description:protected] => TinCan\LanguageMap Object
(
[_map:protected] => Array
(
)
)
[moreInfo:protected] =>
[extensions:protected] => TinCan\Extensions Object
(
[_map:protected] => Array
(
)
)
[interactionType:protected] =>
[correctResponsesPattern:protected] =>
[choices:protected] =>
[scale:protected] =>
[source:protected] =>
[target:protected] =>
[steps:protected] =>
)
)
)
[parent:protected] => Array
(
)
[grouping:protected] => Array
(
)
[other:protected] => Array
(
)
)
[revision:protected] =>
[platform:protected] =>
[language:protected] =>
[statement:protected] =>
[extensions:protected] => TinCan\Extensions Object
(
[_map:protected] => Array
(
)
)
)
[timestamp:protected] => 2018-02-24T04:21:22.456Z
)
...
+ 100 more like these.
I get this output after running my php code to retrive all information from the LRS. How to change this into PHP ARRAY?
You need to learn how to use their API documentation, There is no simple "get all the data" that I can see because everything is wrapped in a class with private/protected properties....
Using your provided sample, here is an example of how to "get the actors"
$Statements = getAllActivity()->content->getStatements();
foreach( $Statements as $Statement )
{
print_r( $Statement->getActor() );
print_r( $Statement->getActor()->getName() );
print_r( $Statement->getActor()->getMbox() );
}
Review the script \src\StatementBase.php, this is where I found the getAcator() method
Without your php code I can only assume you are using json_decode($response) instead of json_decode($response, true). Second parameter in this function decides whether to decode into a class as you have or simple array.

How to get value from the given object response from Twinfield in Laravel/Lumen?

This is the response when I call the login method from twinfield API. It given the session id and cluster namespace, but the problem is how to get the value from it.
$customerApiConnector = new \PhpTwinfield\ApiConnectors\CustomerApiConnector($login);
print_r($customerApiConnector);die;
Output:
PhpTwinfield\ApiConnectors\CustomerApiConnector Object
(
[service:protected] => PhpTwinfield\Services\ProcessXmlService Object
(
[trace] => 1
[compression] => 32
[_stream_context] => Resource id #153
[_soap_version] => 1
[sdl] => Resource id #154
[__default_headers] => Array
(
[0] => SoapHeader Object
(
[namespace] => http://www.twinfield.com/
[name] => Header
[data] => Array
(
[SessionID] => f7b4c213-1a01-4c7c-87cb-7de80b1583fe
)
[mustUnderstand] =>
)
)
)
)
This is the other object.
Array
(
[1] => PhpTwinfield\CustomerAddress Object
(
[ID:PhpTwinfield\CustomerAddress:private] => 1
[type:PhpTwinfield\CustomerAddress:private] => invoice
[default:PhpTwinfield\CustomerAddress:private] => true
[name:PhpTwinfield\CustomerAddress:private] => Anand
[contact:PhpTwinfield\CustomerAddress:private] =>
[country:PhpTwinfield\CustomerAddress:private] => IN
[city:PhpTwinfield\CustomerAddress:private] => Indore
[postcode:PhpTwinfield\CustomerAddress:private] => 452001
[telephone:PhpTwinfield\CustomerAddress:private] =>
[fax:PhpTwinfield\CustomerAddress:private] =>
[email:PhpTwinfield\CustomerAddress:private] => anand#comfisoft.com
[field1:PhpTwinfield\CustomerAddress:private] =>
[field2:PhpTwinfield\CustomerAddress:private] => lig
[field4:PhpTwinfield\CustomerAddress:private] =>
[field5:PhpTwinfield\CustomerAddress:private] =>
[field6:PhpTwinfield\CustomerAddress:private] =>
)
)
Try this it will work ;)
function accessProtectedProperty($obj, $prop)
{
$reflection = new \ReflectionClass($obj);
$property = $reflection->getProperty($prop);
$property->setAccessible(true);
return json_decode($property->getValue($obj));
}

how to read values from an assosiative array using php?

This is my sample associative array:
Array (
[0] => Array (
[Name] => ALCOIN
[BasePlugin] => HTTP
[Version] => 1
[Description] => Plugin for ALCO_IN operations
[ImagePath] => ./resources
[xip] => http://www.example.org/XIP
[xsi] => http://www.w3.org/2001/XMLSchema-instance
[schemaLocation] => http://www.example.org/XIP XIP.xsd
)
[1] => Array (
[xip:Action] => Array (
[#attributes] => Array (
[Name] => OfferActivationByOfferID
[Version] => 1.0
[ImagePath] => ./resources
)
)
)
)
In that array I need to get the BasePlugin value and the name attribute value.
It seems you might need this:
$basePlugin = $yourArray[0]['BasePlugin'];
$attributes = $yourArray[1]['xip:Action']['#attributes'];
Assuming you are assigned to $yourVar like:
$yourVar = Array (
[0] => Array (
[Name] => ALCOIN
[BasePlugin] => HTTP
[Version] => 1
[Description] => Plugin for ALCO_IN operations
[ImagePath] => ./resources
[xip] => http://www.example.org/XIP
[xsi] => http://www.w3.org/2001/XMLSchema-instance
[schemaLocation] => http://www.example.org/XIP XIP.xsd
)
[1] => Array (
[xip:Action] => Array (
[#attributes] => Array (
[Name] => OfferActivationByOfferID
[Version] => 1.0
[ImagePath] => ./resources
)
)
)
)
You would use:
echo $yourVar[0]["BasePlugin"];
echo $yourVar[1]["xip:Action"]["#attributes"]["Name"];
echo $yourVar[1]["xip:Action"]["#attributes"]["Version"];
echo $yourVar[1]["xip:Action"]["#attributes"]["ImagePath"];

Categories