how to update a new session in multidimensional array in codeigniter? - php

this is my session which will be show by $order_id
["items_250"]=>
array(4) {
["menu_0"]=>
array(4) {
["user_order_id"]=>
string(3) " 86"
["menu_id"]=>
string(3) "231"
["qty"]=>
string(1) "1"
["choice"]=>
array(1) {
[0]=>
string(1) "3"
}
}
["menu_1"]=>
array(4) {
["user_order_id"]=>
string(3) " 86"
["menu_id"]=>
string(3) "236"
["qty"]=>
string(1) "1"
["choice"]=>
array(1) {
[0]=>
string(0) ""
}
}
["menu_2"]=>
array(4) {
["user_order_id"]=>
string(3) " 86"
["menu_id"]=>
string(3) "232"
["qty"]=>
string(1) "1"
["choice"]=>
array(1) {
[0]=>
string(0) ""
}
}
["menu_3"]=>
array(4) {
["user_order_id"]=>
string(3) " 86"
["menu_id"]=>
string(3) "357"
["qty"]=>
string(1) "1"
["choice"]=>
array(1) {
[0]=>
string(0) ""
}
}
}
i want if i used another $oder_id it will show only the session by the $order_id, example my first order_id is 86, it will showed as the first session on top,
than if i used new $order_id example 83, it will show :
["items_250"]=>
array(4) {
["menu_0"]=>
array(4) {
["user_order_id"]=>
string(2) "83"
["menu_id"]=>
string(3) "236"
["qty"]=>
string(1) "1"
["choice"]=>
array(1) {
[0]=>
string(0) ""
}
}
["menu_1"]=>
array(4) {
["user_order_id"]=>
string(2) "83"
["menu_id"]=>
string(3) "357"
["qty"]=>
string(1) "1"
["choice"]=>
array(1) {
[0]=>
string(0) ""
}
}
but if i used another $order_id
it will be showed this :
["items_250"]=>
array(4) {
["menu_0"]=>
array(4) {
["user_order_id"]=>
string(2) "83"
["menu_id"]=>
string(3) "236"
["qty"]=>
string(1) "1"
["choice"]=>
array(1) {
[0]=>
string(0) ""
}
}
["menu_1"]=>
array(4) {
["user_order_id"]=>
string(2) "83"
["menu_id"]=>
string(3) "357"
["qty"]=>
string(1) "1"
["choice"]=>
array(1) {
[0]=>
string(0) ""
}
}
["menu_2"]=>
array(4) {
["user_order_id"]=>
string(3) " 86"
["menu_id"]=>
string(3) "232"
["qty"]=>
string(1) "1"
["choice"]=>
array(1) {
[0]=>
string(0) ""
}
}
["menu_3"]=>
array(4) {
["user_order_id"]=>
string(3) " 86"
["menu_id"]=>
string(3) "357"
["qty"]=>
string(1) "1"
["choice"]=>
array(1) {
[0]=>
string(0) ""
}
}
}
as you can see from new session, the session of user_order_id are different, but it still showed the last session of user_order_id
this is how i set my session:
if($order_id !== $this->session->userdata('user_order_id')) {
$count = count($menu_id); // get count
for ($i = 0; $i < $count; $i++) {
$_SESSION['items_' . $restaurant_id]['menu_' . $i] = array(
'user_order_id' => $order_id,
'menu_id' => $menu_id[$i],
'qty' => $qty[$i],
"choice" => array($variant_name[$i]['variant_menu_id']),
);
}
}else{
}
guys can you help me how to update the session?

Related

Making a dynamic valuation with foreach php

I want to make a dynamic valuation. So the idea is like this :
In my database I've user table contains 'score'.
And I've category table contains fields 'minScore' and 'categoryName(bad, good, awesome)'
And In the end I want to get result like this categoryName=>howMuchUserBasedOnScore.
I'm thinking like this :
function valuation(){
$allScore = $this->db->select('score')->get('user')->result();
$category = $this->db->get('categori')->result();
$arrCategori = array();
foreach ($allScore as $value) {
foreach($categori as $row){
if($value->score <= $row->minScore){
array_push($arrCategori, )
//I don't know what should I do
}
}
}
}
can anyone help me?
edit :
Now I add maxScore into my category table field.
and I changed the if statement. it become like this
if($value->score <= $row->minScore && $value->score >= $row->maxScore){
array_push($arrCategori, $arrCategori[$row->Categori] = $value->bsc );
}
I var_dump it. and the result is what I expected. the problem now is that, how can I count how much people that are awesome, bad or good
edit :
here's the var_dump from $allscore (I change bsc into score for the sake simplicity):
array(11) { [0]=> object(stdClass)#42 (1) { ["bsc"]=> string(6) "100.00" } [1]=> object(stdClass)#43 (1) { ["bsc"]=> string(5) "40.00" } [2]=> object(stdClass)#44 (1) { ["bsc"]=> string(6) "100.00" } [3]=> object(stdClass)#45 (1) { ["bsc"]=> string(6) "100.00" } [4]=> object(stdClass)#46 (1) { ["bsc"]=> string(5) "40.00" } [5]=> object(stdClass)#47 (1) { ["bsc"]=> string(5) "40.00" } [6]=> object(stdClass)#48 (1) { ["bsc"]=> string(5) "40.00" } [7]=> object(stdClass)#49 (1) { ["bsc"]=> string(5) "40.00" } [8]=> object(stdClass)#50 (1) { ["bsc"]=> string(5) "40.00" } [9]=> object(stdClass)#51 (1) { ["bsc"]=> string(5) "60.00" } [10]=> object(stdClass)#52 (1) { ["bsc"]=> string(4) "0.00" } }
var_dump from $category (bxnak = maxScore, bxnaw = minScore)
array(9) { [0]=> object(stdClass)#53 (4) { ["id"]=> string(1) "1" ["bxnaw"]=> string(1) "0" ["bxnak"]=> string(2) "25" ["kategori"]=> string(5) "GAGAL" } [1]=> object(stdClass)#54 (4) { ["id"]=> string(1) "2" ["bxnaw"]=> string(2) "26" ["bxnak"]=> string(2) "40" ["kategori"]=> string(16) "DALAM PENGAWASAN" } [2]=> object(stdClass)#55 (4) { ["id"]=> string(1) "3" ["bxnaw"]=> string(2) "41" ["bxnak"]=> string(2) "50" ["kategori"]=> string(18) "PERLU PENGEMBANGAN" } [3]=> object(stdClass)#56 (4) { ["id"]=> string(1) "4" ["bxnaw"]=> string(2) "51" ["bxnak"]=> string(2) "60" ["kategori"]=> string(5) "BURUK" } [4]=> object(stdClass)#57 (4) { ["id"]=> string(1) "5" ["bxnaw"]=> string(2) "61" ["bxnak"]=> string(2) "75" ["kategori"]=> string(11) "KURANG BAIK" } [5]=> object(stdClass)#58 (4) { ["id"]=> string(1) "6" ["bxnaw"]=> string(2) "76" ["bxnak"]=> string(2) "80" ["kategori"]=> string(10) "CUKUP BAIK" } [6]=> object(stdClass)#59 (4) { ["id"]=> string(1) "7" ["bxnaw"]=> string(2) "81" ["bxnak"]=> string(2) "90" ["kategori"]=> string(4) "BAIK" } [7]=> object(stdClass)#60 (4) { ["id"]=> string(1) "8" ["bxnaw"]=> string(2) "91" ["bxnak"]=> string(2) "99" ["kategori"]=> string(11) "SANGAT BAIK" } [8]=> object(stdClass)#61 (4) { ["id"]=> string(1) "9" ["bxnaw"]=> string(3) "100" ["bxnak"]=> string(4) "1000" ["kategori"]=> string(8) "ISTIMEWA" } }
I finally did it!!
so here's the final code of my function
function valuation(){
$allBsc = $this->db->select('bsc')->get('kpi')->result();
$kategori = $this->db->get('kategori')->result();
$arrKategori = [];
foreach ($allBsc as $value) {
foreach($kategori as $row){
if($value->bsc <= $row->bxnak && $value->bsc >= $row->bxnaw){
if(array_key_exists($row->kategori, $arrKategori)){
array_push($arrKategori[$row->kategori], $value->bsc);
}else{
array_push($arrKategori, $arrKategori[$row->kategori] = array($value->bsc));
}
}
}
}
var_dump(count($arrKategori));
die();
}
thank you, for helping me!
$allBsc = $score
$kategori = $category
$arrKategori = $allCategory

Php getting data out of an array

I have a massive array that i can't get data out of. I can only get data out of the first set of items.
I need to get to
["USFICO"]=>
array(3) {
["FICOScore"]=>
string(5) "00650"
out of it. But i can only get the top portion to work w/ $tester = $array['EfxReport']['#attributes']['reportId']; outputs to string(22) "USConsumerCreditReport" as expected.
how can i get the FICO score out of this array.
Here is the array.
array(1) {
["EfxReport"]=>
array(3) {
["#attributes"]=>
array(2) {
["requestNumber"]=>
string(1) "1"
["reportId"]=>
string(22) "USConsumerCreditReport"
}
["USDecisionPowerExpressReports"]=>
array(1) {
["USDecisionPowerExpressReport"]=>
array(4) {
["#attributes"]=>
array(2) {
["subjectType"]=>
string(7) "Subject"
["multipleNumber"]=>
string(1) "1"
}
["USMasterHeader"]=>
array(5) {
["CustomerReferenceNumber"]=>
string(6) "EFX QA"
["CustomerNumber"]=>
string(10) "999KI00553"
["ECOAInquiryType"]=>
string(1) "I"
["DateOfRequest"]=>
string(10) "02/23/2017"
["EquifaxReferenceNumber"]=>
string(9) "187391427"
}
["USConsumerCreditReport"]=>
array(6) {
["#attributes"]=>
array(2) {
["subjectType"]=>
string(7) "Subject"
["multipleNumber"]=>
string(1) "1"
}
["USHeader"]=>
array(3) {
["Request"]=>
array(6) {
["CustomerReferenceNumber"]=>
string(6) "EFX QA"
["CustomerNumber"]=>
string(10) "999KI00553"
["ConsumerReferralCode"]=>
string(3) "024"
["ECOAInquiryType"]=>
string(1) "I"
["NumberOfMonthsToCountInquiries"]=>
string(14) "Last 24 Months"
["NumberOfMonthsToCountDelinquencies"]=>
string(23) "Last 6 Years, 11 Months"
}
["CreditFile"]=>
array(11) {
["HitCode"]=>
array(1) {
["#attributes"]=>
array(2) {
["code"]=>
string(1) "1"
["description"]=>
string(3) "Hit"
}
}
["FileSinceDate"]=>
string(10) "04/16/2003"
["DateOfLastActivity"]=>
string(10) "01/24/2017"
["DateOfRequest"]=>
string(10) "02/23/2017"
["Identityscans"]=>
array(1) {
["Identityscan"]=>
array(1) {
["#attributes"]=>
array(2) {
["code"]=>
string(1) "8"
["description"]=>
string(74) "Unable to perform telephone validation due to insufficient telephone input"
}
}
}
["AddressDiscrepancyIndicator"]=>
string(1) "N"
["CreateCode"]=>
string(1) "2"
["FileStatus1"]=>
string(3) "016"
["FileStatus2"]=>
string(3) "242"
["FileStatus3"]=>
string(3) "004"
["BureauCode"]=>
string(3) "244"
}
["Subject"]=>
array(2) {
["SubjectName"]=>
array(3) {
["LastName"]=>
string(7) "DGNNLXZ"
["FirstName"]=>
string(7) "CHANITA"
["MiddleName"]=>
string(1) "S"
}
["SubjectId"]=>
array(2) {
["SubjectSSN"]=>
string(8) "66639074"
["DateOfBirth"]=>
string(10) "08/17/1988"
}
}
}
["USAddresses"]=>
array(1) {
["USAddress"]=>
array(3) {
[0]=>
array(8) {
["#attributes"]=>
array(2) {
["code"]=>
string(2) "CA"
["description"]=>
string(15) "Current Address"
}
["ParsedStreetAddress"]=>
array(3) {
["StreetNumber"]=>
string(4) "4338"
["StreetName"]=>
string(9) "W POTOMAC"
["StreetType"]=>
string(3) "AVE"
}
["City"]=>
string(7) "CHICAGO"
["State"]=>
string(2) "IL"
["PostalCode"]=>
string(5) "60651"
["DateAddressFirstReported"]=>
string(7) "07/2015"
["AddressSource"]=>
array(1) {
["#attributes"]=>
array(2) {
["code"]=>
string(1) "T"
["description"]=>
string(4) "Tape"
}
}
["DateAddressLastReported"]=>
string(7) "02/2017"
}
[1]=>
array(8) {
["#attributes"]=>
array(2) {
["code"]=>
string(2) "FA"
["description"]=>
string(14) "Former Address"
}
["ParsedStreetAddress"]=>
array(3) {
["StreetNumber"]=>
string(4) "1301"
["StreetName"]=>
string(7) "BRUMMEL"
["StreetType"]=>
string(8) "ST APT 8"
}
["City"]=>
string(8) "EVANSTON"
["State"]=>
string(2) "IL"
["PostalCode"]=>
string(5) "60202"
["DateAddressFirstReported"]=>
string(7) "04/2015"
["AddressSource"]=>
array(1) {
["#attributes"]=>
array(2) {
["code"]=>
string(1) "T"
["description"]=>
string(4) "Tape"
}
}
["DateAddressLastReported"]=>
string(7) "04/2015"
}
[2]=>
array(8) {
["#attributes"]=>
array(2) {
["code"]=>
string(2) "F2"
["description"]=>
string(21) "Second Former Address"
}
["ParsedStreetAddress"]=>
array(3) {
["StreetNumber"]=>
string(4) "1208"
["StreetName"]=>
string(11) "W JEFFERSON"
["StreetType"]=>
string(8) "ST APT C"
}
["City"]=>
string(11) "SPRINGFIELD"
["State"]=>
string(2) "IL"
["PostalCode"]=>
string(5) "62702"
["DateAddressFirstReported"]=>
string(7) "06/2014"
["AddressSource"]=>
array(1) {
["#attributes"]=>
array(2) {
["code"]=>
string(1) "T"
["description"]=>
string(4) "Tape"
}
}
["DateAddressLastReported"]=>
string(7) "06/2014"
}
}
}
["USEmployments"]=>
array(1) {
["USEmployment"]=>
array(3) {
["#attributes"]=>
array(2) {
["code"]=>
string(2) "ES"
["description"]=>
string(24) "Last Reported Employment"
}
["Occupation"]=>
string(14) "CORRECTION OFF"
["Employer"]=>
string(18) "MACON STATE PRISON"
}
}
["USFICO"]=>
array(3) {
["FICOScore"]=>
string(5) "00650"
["ScoreReasons"]=>
array(1) {
["ScoreReason"]=>
array(4) {
[0]=>
array(1) {
["#attributes"]=>
array(3) {
["code"]=>
string(5) "00038"
["description"]=>
string(69) "Serious delinquency, and derogatory public record or collection filed"
["number"]=>
string(1) "1"
}
}
[1]=>
array(1) {
["#attributes"]=>
array(3) {
["code"]=>
string(5) "00010"
["description"]=>
string(76) "Prop of balances to credit limits is too high on bank rev or other rev accts"
["number"]=>
string(1) "2"
}
}
[2]=>
array(1) {
["#attributes"]=>
array(3) {
["code"]=>
string(5) "00018"
["description"]=>
string(35) "Number of accounts with delinquency"
["number"]=>
string(1) "3"
}
}
[3]=>
array(1) {
["#attributes"]=>
array(3) {
["code"]=>
string(5) "00014"
["description"]=>
string(45) "Length of time accounts have been established"
["number"]=>
string(1) "4"
}
}
}
}
["ScoreIndicator"]=>
array(1) {
["#attributes"]=>
array(2) {
["code"]=>
string(1) "J"
["description"]=>
string(39) "FICO Score 5 based on Equifax Data (NF)"
}
}
}
["USIdentificationSSN"]=>
array(4) {
["MDBSubjectSSN"]=>
string(9) "666390749"
["InquirySubjectSSN"]=>
string(9) "666390749"
["InquirySSNDateIssued"]=>
string(4) "1992"
["InquirySSNStateIssued"]=>
string(2) "GA"
}
}
["USDecisionPowerExpressSegment"]=>
array(4) {
["ConsumerDisclosureIndicator"]=>
array(0) {
}
["ReportTextMessage"]=>
string(7) "OFFER C"
["SSNVarianceIndicator"]=>
array(0) {
}
["DPExpressProducts"]=>
array(1) {
["DPExpressProduct"]=>
array(4) {
[0]=>
array(5) {
["#attributes"]=>
array(1) {
["number"]=>
string(1) "1"
}
["Description"]=>
string(1) "A"
["ApprovalIndicator"]=>
string(1) "N"
["Limit"]=>
array(0) {
}
["Miscellaneous"]=>
array(0) {
}
}
[1]=>
array(5) {
["#attributes"]=>
array(1) {
["number"]=>
string(1) "2"
}
["Description"]=>
string(1) "B"
["ApprovalIndicator"]=>
string(1) "N"
["Limit"]=>
array(0) {
}
["Miscellaneous"]=>
array(0) {
}
}
[2]=>
array(5) {
["#attributes"]=>
array(1) {
["number"]=>
string(1) "3"
}
["Description"]=>
string(1) "C"
["ApprovalIndicator"]=>
string(1) "Y"
["Limit"]=>
array(0) {
}
["Miscellaneous"]=>
array(0) {
}
}
[3]=>
array(5) {
["#attributes"]=>
array(1) {
["number"]=>
string(1) "4"
}
["Description"]=>
string(1) "D"
["ApprovalIndicator"]=>
string(1) "N"
["Limit"]=>
array(0) {
}
["Miscellaneous"]=>
array(0) {
}
}
}
}
}
}
}
["USPrintImage"]=>
array(0) {
}
}
}
What's the error you're getting? Try:
$tester = $array['EfxReport']['USDecisionPowerExpressReports']['USDecisionPowerExpressReport']['USConsumerCreditReport']['USFICO']['FICOScore'];
Also I really hope this is fake data, you've included very personal/sensitive information in your array printout.

php session multidimensional array

$_SESSION['items_' . $restaurant_id]["menu_0"] = array(
order_id" => $order_id,
'user_order_id' => $last_order["user_order_id"],
"menu_id" => $menu_id,
"qty" => $qty,
);
that code is my session and will be return become this :
["items_250"]=>
array(2) {
["menu_0"]=>
array(3) {
["user_order_id"]=>
string(2) "85"
["menu_id"]=>
array(3) {
[0]=>
string(2) "236"
[1]=>
string(2) "357"
[2]=>
string(2) "232"
}
["qty"]=>
array(3) {
[0]=>
string(1) "1"
[1]=>
string(1) "1"
[2]=>
string(1) "1"
}
}
in my `$menu_id is array :
array(4) {
[0]=>
string(3) "236"
[1]=>
string(3) "357"
[3]=>
string(3) "232"
}
this is my $qty :
array(3) {
[0]=>
string(1) "1"
[1]=>
string(1) "1"
[2]=>
string(1) "1"
}
i want trying to make my session will be return like this :
["items_250"]=>
array(3) {
["menu_0"]=>
array(3) {
["user_order_id"]=>
string(2) "85"
["menu_id"]=>
string(3) "236"
["qty"]=>
int(1)
}
["menu_1"]=>
array(3) {
["user_order_id"]=>
string(2) "85"
["menu_id"]=>
string(3) "357"
["qty"]=>
int(1)
}
["menu_2"]=>
array(3) {
["user_order_id"]=>
string(2) "85"
["menu_id"]=>
string(3) "232"
["qty"]=>
int(1)
}
guys can you help me how to make my session become like that?
thank you (:
Just use good ol' for loop. First get the count, then create the necessary rows:
$count = count($menu_id); // get count
for($i = 0; $i < $count; $i++) {
$_SESSION['items_' . $restaurant_id]['menu_' . $i] = array(
'user_order_id' => $last_order['user_order_id'],
'menu_id' => $menu_id[$i],
'qty' => $qty[$i],
);
}

PHP current() returns false when passing a valid array to it

i have an array with size=1 and when i try to get the current array its returns false but the array has values.
$article=getArticle($id);
if(is_array($article))
{ $article=current($article); }
the getArticle returns multidimensional array and when var_dump before current i can see the array.
If var_dump after current i get false.
if i use the code above (because the array size=1)
if(is_array($article))
{
foreach($article as $k=>$v)
{
$article=$v;
}
}
It works without any problem
Whats wrong with current?
Please help
===============EDIT========================
This is the var_dump before current
I have remove the content and summary because are large texts
array(1) {
[529]=>
array(14) {
["articles_id"]=>
string(3) "529"
["issue"]=>
string(3) "161"
["membership_type"]=>
string(1) "1"
["el"]=>
array(9) {
["title"]=>
string(23) "AUTOBIANCHI A112 ABARTH"
["url"]=>
string(23) "autobianchi-a112-abarth"
["summary"]=>
string(397) " i have remove it
"
["content"]=>
string(11580) " i have remove it too large
"
["meta_keywords"]=>
string(23) "AUTOBIANCHI,A112,ABARTH"
["meta_description"]=>
string(402) " "
["created"]=>
string(10) "1362076380"
["last_updated"]=>
string(1) "0"
["status"]=>
string(1) "1"
}
["categories_id"]=>
string(2) "12"
["authors_id"]=>
string(2) "16"
["brands_id"]=>
string(2) "36"
["models_id"]=>
string(3) "206"
["engines_id"]=>
string(3) "174"
["o-categories"]=>
array(1) {
["values"]=>
array(1) {
[12]=>
array(15) {
["categories_id"]=>
string(2) "12"
["object_id"]=>
string(1) "1"
["parent_id"]=>
string(1) "0"
["path"]=>
string(2) "12"
["handler"]=>
string(0) ""
["icon"]=>
string(0) ""
["tpl"]=>
string(12) "articles.php"
["alias"]=>
string(1) "0"
["is_nav"]=>
string(1) "1"
["pos"]=>
string(2) "10"
["depth"]=>
string(1) "0"
["cts"]=>
string(0) ""
["mts"]=>
string(0) ""
["configuration"]=>
string(0) ""
["el"]=>
array(15) {
["categories_id"]=>
string(2) "12"
["lang"]=>
string(2) "el"
["category_name"]=>
string(13) "Classic"
["sub_title"]=>
string(0) ""
["summary"]=>
string(0) ""
["image"]=>
string(0) ""
["html_code"]=>
string(0) ""
["meta_title"]=>
string(0) ""
["url"]=>
string(13) "classic"
["url_path"]=>
string(13) "classic"
["meta_keywords"]=>
string(0) ""
["meta_description"]=>
string(0) ""
["created"]=>
string(10) "1355235888"
["last_updated"]=>
string(1) "0"
["status"]=>
string(1) "1"
}
}
}
}
["o-authors"]=>
array(1) {
["values"]=>
array(1) {
[16]=>
array(4) {
["authors_id"]=>
string(2) "16"
["object_id"]=>
string(2) "26"
["image"]=>
string(0) ""
["el"]=>
array(9) {
["authors_id"]=>
string(2) "16"
["lang"]=>
string(2) "el"
["name"]=>
string(31) "Last First"
["last_name"]=>
string(10) "Last"
["first_name"]=>
string(20) "First"
["nick_name"]=>
string(0) ""
["created"]=>
string(10) "1360567827"
["last_updated"]=>
string(1) "0"
["status"]=>
string(1) "1"
}
}
}
}
["o-brands"]=>
array(1) {
["values"]=>
array(1) {
[36]=>
array(6) {
["brands_id"]=>
string(2) "36"
["object_id"]=>
string(2) "17"
["brand_name"]=>
string(11) "AUTOBIANCHI"
["created"]=>
string(10) "1363179463"
["last_updated"]=>
string(1) "0"
["status"]=>
string(1) "1"
}
}
}
["o-models"]=>
array(1) {
["values"]=>
array(1) {
[206]=>
array(7) {
["models_id"]=>
string(3) "206"
["object_id"]=>
string(2) "18"
["brands_id"]=>
string(2) "36"
["model_name"]=>
string(11) "A112 ABARTH"
["created"]=>
string(10) "1363179480"
["last_updated"]=>
string(1) "0"
["status"]=>
string(1) "1"
}
}
}
["o-engines"]=>
array(1) {
["values"]=>
array(1) {
[174]=>
array(6) {
["engines_id"]=>
string(3) "174"
["object_id"]=>
string(2) "19"
["engine"]=>
string(5) "1.050"
["created"]=>
string(10) "1363179448"
["last_updated"]=>
string(1) "0"
["status"]=>
string(1) "1"
}
}
}
}
}
Can you try
$article=getArticle($id);
if (is_array($article)) {
$article = reset($article);
}
or
$article=getArticle($id);
if (is_array($article)) {
$article = array_shift($article);
}
You can look into the documentation about reset and the documentation about array_shift.
If you copy array in getArticle() function then its internal pointer is lost.
I think this is the reason, it returns false.

How to get object(stdClass) from array

Given the array below, how do I get values of object(stdClass) such as Pcv (campus Aalst), Mss ( Privaatpraktijk kinesitherapie Peeters Stefaan ), and so on?
array(106) {
[0]=>
object(stdClass)#8 (45) {
["nid"]=>
string(3) "199"
["type"]=>
string(11) "stageplaats"
["language"]=>
string(2) "nl"
["uid"]=>
string(2) "33"
["status"]=>
string(1) "1"
["created"]=>
string(10) "1291279334"
["changed"]=>
string(10) "1301323146"
["comment"]=>
string(1) "0"
["promote"]=>
string(1) "0"
["moderate"]=>
string(1) "0"
["sticky"]=>
string(1) "0"
["tnid"]=>
string(1) "0"
["translate"]=>
string(1) "0"
["vid"]=>
string(3) "206"
["revision_uid"]=>
string(2) "16"
["title"]=>
string(18) "Pcv (campus Aalst)"
["body"]=>
string(0) ""
["teaser"]=>
string(0) ""
["log"]=>
string(0) ""
["revision_timestamp"]=>
string(10) "1301323146"
["format"]=>
string(1) "0"
["nd_switch_bm"]=>
string(0) ""
["name"]=>
string(12) "stage.revaki"
["picture"]=>
string(0) ""
["data"]=>
string(72) "a:1:{s:13:"form_build_id";s:37:"form-f89b99e4a5249b192ff472579b826b00";}"
["field_stagedomein_audiologo"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_stagedomein_geneeskunde"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_stagedomein_lo"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_stagedomein_revaki"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(3) "152"
}
}
["field_stagedomein_verpleeg"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_status"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(14) "niet opgegeven"
}
}
["field_status_datum"]=>
array(1) {
[0]=>
array(4) {
["value"]=>
NULL
["timezone"]=>
string(15) "Europe/Brussels"
["timezone_db"]=>
string(15) "Europe/Brussels"
["date_type"]=>
string(4) "date"
}
}
["field_locatieview"]=>
array(1) {
[0]=>
array(1) {
["nid"]=>
string(3) "179"
}
}
["field_status_extra"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_status_stagedomein"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(6) "Actief"
}
}
["field_maxcapstud_stagedomein"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(2) "18"
}
}
["field_status_bevestigd_door"]=>
array(1) {
[0]=>
array(1) {
["nid"]=>
NULL
}
}
["field_aanpers_stageplaats"]=>
array(1) {
[0]=>
array(1) {
["nid"]=>
NULL
}
}
["field_extrainfo_stagedomein"]=>
array(1) {
[0]=>
array(2) {
["value"]=>
string(37) "Capaciteit: 3 studenten alle periodes"
["format"]=>
NULL
}
}
["field_percapaciteit_stageplaats"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_aanplaats_stageplaats"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_mentoren"]=>
array(1) {
[0]=>
array(1) {
["nid"]=>
string(3) "178"
}
}
["field_persoon_stagedomein"]=>
array(1) {
[0]=>
array(1) {
["nid"]=>
NULL
}
}
["has_body"]=>
string(1) "0"
["taxonomy"]=>
array(0) {
}
}
[1]=>
object(stdClass)#24 (45) {
["nid"]=>
string(3) "211"
["type"]=>
string(11) "stageplaats"
["language"]=>
string(2) "nl"
["uid"]=>
string(2) "33"
["status"]=>
string(1) "1"
["created"]=>
string(10) "1291281467"
["changed"]=>
string(10) "1301323440"
["comment"]=>
string(1) "0"
["promote"]=>
string(1) "0"
["moderate"]=>
string(1) "0"
["sticky"]=>
string(1) "0"
["tnid"]=>
string(1) "0"
["translate"]=>
string(1) "0"
["vid"]=>
string(3) "218"
["revision_uid"]=>
string(2) "16"
["title"]=>
string(53) "Mss ( Privaatpraktijk kinesitherapie Walravens Marc )"
["body"]=>
string(0) ""
["teaser"]=>
string(0) ""
["log"]=>
string(0) ""
["revision_timestamp"]=>
string(10) "1301323440"
["format"]=>
string(1) "0"
["nd_switch_bm"]=>
string(0) ""
["name"]=>
string(12) "stage.revaki"
["picture"]=>
string(0) ""
["data"]=>
string(72) "a:1:{s:13:"form_build_id";s:37:"form-f89b99e4a5249b192ff472579b826b00";}"
["field_stagedomein_audiologo"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_stagedomein_geneeskunde"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_stagedomein_lo"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_stagedomein_revaki"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(3) "128"
}
}
["field_stagedomein_verpleeg"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_status"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(14) "niet opgegeven"
}
}
["field_status_datum"]=>
array(1) {
[0]=>
array(4) {
["value"]=>
NULL
["timezone"]=>
string(15) "Europe/Brussels"
["timezone_db"]=>
string(15) "Europe/Brussels"
["date_type"]=>
string(4) "date"
}
}
["field_locatieview"]=>
array(1) {
[0]=>
array(1) {
["nid"]=>
string(3) "210"
}
}
["field_status_extra"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_status_stagedomein"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(6) "Actief"
}
}
["field_maxcapstud_stagedomein"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
string(1) "4"
}
}
["field_status_bevestigd_door"]=>
array(1) {
[0]=>
array(1) {
["nid"]=>
NULL
}
}
["field_aanpers_stageplaats"]=>
array(1) {
[0]=>
array(1) {
["nid"]=>
NULL
}
}
["field_extrainfo_stagedomein"]=>
array(1) {
[0]=>
array(2) {
["value"]=>
string(40) "Capaciteit: 1 student in periode 3 tem 6"
["format"]=>
NULL
}
}
["field_percapaciteit_stageplaats"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_aanplaats_stageplaats"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_mentoren"]=>
array(1) {
[0]=>
array(1) {
["nid"]=>
string(3) "208"
}
}
["field_persoon_stagedomein"]=>
array(1) {
[0]=>
array(1) {
["nid"]=>
NULL
}
}
["has_body"]=>
string(1) "0"
["taxonomy"]=>
array(0) {
}
}
[2]=>
object(stdClass)#26 (45) {
["nid"]=>
string(3) "217"
["type"]=>
string(11) "stageplaats"
["language"]=>
string(2) "nl"
["uid"]=>
string(2) "33"
["status"]=>
string(1) "1"
["created"]=>
string(10) "1291281906"
["changed"]=>
string(10) "1301323440"
["comment"]=>
string(1) "0"
["promote"]=>
string(1) "0"
["moderate"]=>
string(1) "0"
["sticky"]=>
string(1) "0"
["tnid"]=>
string(1) "0"
["translate"]=>
string(1) "0"
["vid"]=>
string(3) "224"
["revision_uid"]=>
string(2) "16"
["title"]=>
string(54) "Mss ( Privaatpraktijk kinesitherapie Peeters Stefaan )"
["body"]=>
string(0) ""
["teaser"]=>
string(0) ""
["log"]=>
string(0) ""
["revision_timestamp"]=>
string(10) "1301323440"
["format"]=>
string(1) "0"
["nd_switch_bm"]=>
string(0) ""
["name"]=>
string(12) "stage.revaki"
["picture"]=>
string(0) ""
["data"]=>
string(72) "a:1:{s:13:"form_build_id";s:37:"form-f89b99e4a5249b192ff472579b826b00";}"
["field_stagedomein_audiologo"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_stagedomein_geneeskunde"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
["field_stagedomein_lo"]=>
array(1) {
[0]=>
array(1) {
["value"]=>
NULL
}
}
The object is at the index 0 in the array, so you just access the property names from there
echo $theArray[0]->title;
For more information, please see the PHP manual's Language Reference, especially
the chapter on Arrays and
the chapter on Objects

Categories