Check if array index is 1 in PHP array
This bit of code picks up an array containing 3 indexes:
<?php var_dump($the_query1->posts); ?>
The output is an array of 3 indexes:
array(3) {
[0]=>
object(WP_Post)#4451 (24) {
["ID"]=>
int(19163)
["post_author"]=>
string(1) "2"
["post_date"]=>
string(19) "2018-09-28 15:42:12"
["post_date_gmt"]=>
string(19) "2018-09-28 13:42:12"
["post_content"]=>
string(0) ""
["post_title"]=>
string(16) "Global Factories"
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(6) "closed"
["ping_status"]=>
string(6) "closed"
["post_password"]=>
string(0) ""
["post_name"]=>
string(16) "global-factories"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2018-11-15 12:41:57"
["post_modified_gmt"]=>
string(19) "2018-11-15 11:41:57"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(48) "https://www.zeo.nl/?post_type=cases&p=19163"
["menu_order"]=>
int(0)
["post_type"]=>
string(5) "cases"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
}
[1]=>
object(WP_Post)#4448 (24) {
["ID"]=>
int(19167)
["post_author"]=>
string(1) "2"
["post_date"]=>
string(19) "2018-09-21 14:58:50"
["post_date_gmt"]=>
string(19) "2018-09-21 12:58:50"
["post_content"]=>
string(0) ""
["post_title"]=>
string(24) "Warmteservice Groep B.V."
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(6) "closed"
["ping_status"]=>
string(6) "closed"
["post_password"]=>
string(0) ""
["post_name"]=>
string(13) "warmteservice"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2018-11-15 12:00:56"
["post_modified_gmt"]=>
string(19) "2018-11-15 11:00:56"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(48) "https://www.zeo.nl/?post_type=cases&p=19167"
["menu_order"]=>
int(0)
["post_type"]=>
string(5) "cases"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
}
[2]=>
object(WP_Post)#4556 (24) {
["ID"]=>
int(19157)
["post_author"]=>
string(1) "2"
["post_date"]=>
string(19) "2018-09-21 11:26:12"
["post_date_gmt"]=>
string(19) "2018-09-21 09:26:12"
["post_content"]=>
string(0) ""
["post_title"]=>
string(9) "Blauwtulp"
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(6) "closed"
["ping_status"]=>
string(6) "closed"
["post_password"]=>
string(0) ""
["post_name"]=>
string(11) "blauwtulp-2"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2018-11-15 12:46:48"
["post_modified_gmt"]=>
string(19) "2018-11-15 11:46:48"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(48) "https://www.zeo.nl/?post_type=cases&p=19157"
["menu_order"]=>
int(0)
["post_type"]=>
string(5) "cases"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
}
}
What is the best way to check if the current index is in position 1? I want to return a bool to decide if the element should become <div class="col-sm-4"> or <div class="col-sm-3"> in case true is returned.
I tried this:
<?php var_dump($the_query1->posts[1] === true); ?>
But this is returning three times false. I need to return false, true, false. What is the easiest way to do the check?
php
|
show 1 more comment
This bit of code picks up an array containing 3 indexes:
<?php var_dump($the_query1->posts); ?>
The output is an array of 3 indexes:
array(3) {
[0]=>
object(WP_Post)#4451 (24) {
["ID"]=>
int(19163)
["post_author"]=>
string(1) "2"
["post_date"]=>
string(19) "2018-09-28 15:42:12"
["post_date_gmt"]=>
string(19) "2018-09-28 13:42:12"
["post_content"]=>
string(0) ""
["post_title"]=>
string(16) "Global Factories"
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(6) "closed"
["ping_status"]=>
string(6) "closed"
["post_password"]=>
string(0) ""
["post_name"]=>
string(16) "global-factories"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2018-11-15 12:41:57"
["post_modified_gmt"]=>
string(19) "2018-11-15 11:41:57"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(48) "https://www.zeo.nl/?post_type=cases&p=19163"
["menu_order"]=>
int(0)
["post_type"]=>
string(5) "cases"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
}
[1]=>
object(WP_Post)#4448 (24) {
["ID"]=>
int(19167)
["post_author"]=>
string(1) "2"
["post_date"]=>
string(19) "2018-09-21 14:58:50"
["post_date_gmt"]=>
string(19) "2018-09-21 12:58:50"
["post_content"]=>
string(0) ""
["post_title"]=>
string(24) "Warmteservice Groep B.V."
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(6) "closed"
["ping_status"]=>
string(6) "closed"
["post_password"]=>
string(0) ""
["post_name"]=>
string(13) "warmteservice"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2018-11-15 12:00:56"
["post_modified_gmt"]=>
string(19) "2018-11-15 11:00:56"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(48) "https://www.zeo.nl/?post_type=cases&p=19167"
["menu_order"]=>
int(0)
["post_type"]=>
string(5) "cases"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
}
[2]=>
object(WP_Post)#4556 (24) {
["ID"]=>
int(19157)
["post_author"]=>
string(1) "2"
["post_date"]=>
string(19) "2018-09-21 11:26:12"
["post_date_gmt"]=>
string(19) "2018-09-21 09:26:12"
["post_content"]=>
string(0) ""
["post_title"]=>
string(9) "Blauwtulp"
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(6) "closed"
["ping_status"]=>
string(6) "closed"
["post_password"]=>
string(0) ""
["post_name"]=>
string(11) "blauwtulp-2"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2018-11-15 12:46:48"
["post_modified_gmt"]=>
string(19) "2018-11-15 11:46:48"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(48) "https://www.zeo.nl/?post_type=cases&p=19157"
["menu_order"]=>
int(0)
["post_type"]=>
string(5) "cases"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
}
}
What is the best way to check if the current index is in position 1? I want to return a bool to decide if the element should become <div class="col-sm-4"> or <div class="col-sm-3"> in case true is returned.
I tried this:
<?php var_dump($the_query1->posts[1] === true); ?>
But this is returning three times false. I need to return false, true, false. What is the easiest way to do the check?
php
1
Are you just spamming your question on SO multiple times or is this a completely different problem? It sounds exactly the same as previous 2 or 3 of your questions
– Dharman
Jan 19 at 15:54
The last question didn't solve my problem, so I rephrased the question. Not my intention to spam.
– mdarmanin
Jan 19 at 15:55
2
What do you mean by the current index is in position 1?
– Nigel Ren
Jan 19 at 15:57
where is the code you try that needs tocheck if the current index?
– Pete Houston
Jan 19 at 15:57
2
"so I rephrased the question" - You should edit the existing questions to be clear instead of writing new ones.
– Magnus Eriksson
Jan 19 at 16:06
|
show 1 more comment
This bit of code picks up an array containing 3 indexes:
<?php var_dump($the_query1->posts); ?>
The output is an array of 3 indexes:
array(3) {
[0]=>
object(WP_Post)#4451 (24) {
["ID"]=>
int(19163)
["post_author"]=>
string(1) "2"
["post_date"]=>
string(19) "2018-09-28 15:42:12"
["post_date_gmt"]=>
string(19) "2018-09-28 13:42:12"
["post_content"]=>
string(0) ""
["post_title"]=>
string(16) "Global Factories"
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(6) "closed"
["ping_status"]=>
string(6) "closed"
["post_password"]=>
string(0) ""
["post_name"]=>
string(16) "global-factories"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2018-11-15 12:41:57"
["post_modified_gmt"]=>
string(19) "2018-11-15 11:41:57"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(48) "https://www.zeo.nl/?post_type=cases&p=19163"
["menu_order"]=>
int(0)
["post_type"]=>
string(5) "cases"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
}
[1]=>
object(WP_Post)#4448 (24) {
["ID"]=>
int(19167)
["post_author"]=>
string(1) "2"
["post_date"]=>
string(19) "2018-09-21 14:58:50"
["post_date_gmt"]=>
string(19) "2018-09-21 12:58:50"
["post_content"]=>
string(0) ""
["post_title"]=>
string(24) "Warmteservice Groep B.V."
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(6) "closed"
["ping_status"]=>
string(6) "closed"
["post_password"]=>
string(0) ""
["post_name"]=>
string(13) "warmteservice"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2018-11-15 12:00:56"
["post_modified_gmt"]=>
string(19) "2018-11-15 11:00:56"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(48) "https://www.zeo.nl/?post_type=cases&p=19167"
["menu_order"]=>
int(0)
["post_type"]=>
string(5) "cases"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
}
[2]=>
object(WP_Post)#4556 (24) {
["ID"]=>
int(19157)
["post_author"]=>
string(1) "2"
["post_date"]=>
string(19) "2018-09-21 11:26:12"
["post_date_gmt"]=>
string(19) "2018-09-21 09:26:12"
["post_content"]=>
string(0) ""
["post_title"]=>
string(9) "Blauwtulp"
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(6) "closed"
["ping_status"]=>
string(6) "closed"
["post_password"]=>
string(0) ""
["post_name"]=>
string(11) "blauwtulp-2"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2018-11-15 12:46:48"
["post_modified_gmt"]=>
string(19) "2018-11-15 11:46:48"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(48) "https://www.zeo.nl/?post_type=cases&p=19157"
["menu_order"]=>
int(0)
["post_type"]=>
string(5) "cases"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
}
}
What is the best way to check if the current index is in position 1? I want to return a bool to decide if the element should become <div class="col-sm-4"> or <div class="col-sm-3"> in case true is returned.
I tried this:
<?php var_dump($the_query1->posts[1] === true); ?>
But this is returning three times false. I need to return false, true, false. What is the easiest way to do the check?
php
This bit of code picks up an array containing 3 indexes:
<?php var_dump($the_query1->posts); ?>
The output is an array of 3 indexes:
array(3) {
[0]=>
object(WP_Post)#4451 (24) {
["ID"]=>
int(19163)
["post_author"]=>
string(1) "2"
["post_date"]=>
string(19) "2018-09-28 15:42:12"
["post_date_gmt"]=>
string(19) "2018-09-28 13:42:12"
["post_content"]=>
string(0) ""
["post_title"]=>
string(16) "Global Factories"
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(6) "closed"
["ping_status"]=>
string(6) "closed"
["post_password"]=>
string(0) ""
["post_name"]=>
string(16) "global-factories"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2018-11-15 12:41:57"
["post_modified_gmt"]=>
string(19) "2018-11-15 11:41:57"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(48) "https://www.zeo.nl/?post_type=cases&p=19163"
["menu_order"]=>
int(0)
["post_type"]=>
string(5) "cases"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
}
[1]=>
object(WP_Post)#4448 (24) {
["ID"]=>
int(19167)
["post_author"]=>
string(1) "2"
["post_date"]=>
string(19) "2018-09-21 14:58:50"
["post_date_gmt"]=>
string(19) "2018-09-21 12:58:50"
["post_content"]=>
string(0) ""
["post_title"]=>
string(24) "Warmteservice Groep B.V."
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(6) "closed"
["ping_status"]=>
string(6) "closed"
["post_password"]=>
string(0) ""
["post_name"]=>
string(13) "warmteservice"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2018-11-15 12:00:56"
["post_modified_gmt"]=>
string(19) "2018-11-15 11:00:56"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(48) "https://www.zeo.nl/?post_type=cases&p=19167"
["menu_order"]=>
int(0)
["post_type"]=>
string(5) "cases"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
}
[2]=>
object(WP_Post)#4556 (24) {
["ID"]=>
int(19157)
["post_author"]=>
string(1) "2"
["post_date"]=>
string(19) "2018-09-21 11:26:12"
["post_date_gmt"]=>
string(19) "2018-09-21 09:26:12"
["post_content"]=>
string(0) ""
["post_title"]=>
string(9) "Blauwtulp"
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(6) "closed"
["ping_status"]=>
string(6) "closed"
["post_password"]=>
string(0) ""
["post_name"]=>
string(11) "blauwtulp-2"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2018-11-15 12:46:48"
["post_modified_gmt"]=>
string(19) "2018-11-15 11:46:48"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(48) "https://www.zeo.nl/?post_type=cases&p=19157"
["menu_order"]=>
int(0)
["post_type"]=>
string(5) "cases"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
}
}
What is the best way to check if the current index is in position 1? I want to return a bool to decide if the element should become <div class="col-sm-4"> or <div class="col-sm-3"> in case true is returned.
I tried this:
<?php var_dump($the_query1->posts[1] === true); ?>
But this is returning three times false. I need to return false, true, false. What is the easiest way to do the check?
php
php
asked Jan 19 at 15:52
mdarmaninmdarmanin
90831334
90831334
1
Are you just spamming your question on SO multiple times or is this a completely different problem? It sounds exactly the same as previous 2 or 3 of your questions
– Dharman
Jan 19 at 15:54
The last question didn't solve my problem, so I rephrased the question. Not my intention to spam.
– mdarmanin
Jan 19 at 15:55
2
What do you mean by the current index is in position 1?
– Nigel Ren
Jan 19 at 15:57
where is the code you try that needs tocheck if the current index?
– Pete Houston
Jan 19 at 15:57
2
"so I rephrased the question" - You should edit the existing questions to be clear instead of writing new ones.
– Magnus Eriksson
Jan 19 at 16:06
|
show 1 more comment
1
Are you just spamming your question on SO multiple times or is this a completely different problem? It sounds exactly the same as previous 2 or 3 of your questions
– Dharman
Jan 19 at 15:54
The last question didn't solve my problem, so I rephrased the question. Not my intention to spam.
– mdarmanin
Jan 19 at 15:55
2
What do you mean by the current index is in position 1?
– Nigel Ren
Jan 19 at 15:57
where is the code you try that needs tocheck if the current index?
– Pete Houston
Jan 19 at 15:57
2
"so I rephrased the question" - You should edit the existing questions to be clear instead of writing new ones.
– Magnus Eriksson
Jan 19 at 16:06
1
1
Are you just spamming your question on SO multiple times or is this a completely different problem? It sounds exactly the same as previous 2 or 3 of your questions
– Dharman
Jan 19 at 15:54
Are you just spamming your question on SO multiple times or is this a completely different problem? It sounds exactly the same as previous 2 or 3 of your questions
– Dharman
Jan 19 at 15:54
The last question didn't solve my problem, so I rephrased the question. Not my intention to spam.
– mdarmanin
Jan 19 at 15:55
The last question didn't solve my problem, so I rephrased the question. Not my intention to spam.
– mdarmanin
Jan 19 at 15:55
2
2
What do you mean by the current index is in position 1?
– Nigel Ren
Jan 19 at 15:57
What do you mean by the current index is in position 1?
– Nigel Ren
Jan 19 at 15:57
where is the code you try that needs to
check if the current index?– Pete Houston
Jan 19 at 15:57
where is the code you try that needs to
check if the current index?– Pete Houston
Jan 19 at 15:57
2
2
"so I rephrased the question" - You should edit the existing questions to be clear instead of writing new ones.
– Magnus Eriksson
Jan 19 at 16:06
"so I rephrased the question" - You should edit the existing questions to be clear instead of writing new ones.
– Magnus Eriksson
Jan 19 at 16:06
|
show 1 more comment
1 Answer
1
active
oldest
votes
Use foreach to loop your data and do a condition to match if the array key is 1.
foreach ($the_query1->posts as $key => $value) {
if($key == 1){
echo '<div class="col-sm-3">';
} else {
echo '<div class="col-sm-4">';
}
echo '</div>';
}
When I do a var_dump on $key, I get NULL. Also get NULL for $value.
– mdarmanin
Jan 19 at 16:59
Do the var_dump inside the foreach. You should be able to see the value of the key.
– Emerald
Jan 20 at 8:43
I did the var_dump inside the for loop, but I can't find the log anywhere in console. I've also installed WordPress PHP console, and even there, there is no log being made. Why is that?
– mdarmanin
Jan 20 at 11:09
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54268804%2fcheck-if-array-index-is-1-in-php-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use foreach to loop your data and do a condition to match if the array key is 1.
foreach ($the_query1->posts as $key => $value) {
if($key == 1){
echo '<div class="col-sm-3">';
} else {
echo '<div class="col-sm-4">';
}
echo '</div>';
}
When I do a var_dump on $key, I get NULL. Also get NULL for $value.
– mdarmanin
Jan 19 at 16:59
Do the var_dump inside the foreach. You should be able to see the value of the key.
– Emerald
Jan 20 at 8:43
I did the var_dump inside the for loop, but I can't find the log anywhere in console. I've also installed WordPress PHP console, and even there, there is no log being made. Why is that?
– mdarmanin
Jan 20 at 11:09
add a comment |
Use foreach to loop your data and do a condition to match if the array key is 1.
foreach ($the_query1->posts as $key => $value) {
if($key == 1){
echo '<div class="col-sm-3">';
} else {
echo '<div class="col-sm-4">';
}
echo '</div>';
}
When I do a var_dump on $key, I get NULL. Also get NULL for $value.
– mdarmanin
Jan 19 at 16:59
Do the var_dump inside the foreach. You should be able to see the value of the key.
– Emerald
Jan 20 at 8:43
I did the var_dump inside the for loop, but I can't find the log anywhere in console. I've also installed WordPress PHP console, and even there, there is no log being made. Why is that?
– mdarmanin
Jan 20 at 11:09
add a comment |
Use foreach to loop your data and do a condition to match if the array key is 1.
foreach ($the_query1->posts as $key => $value) {
if($key == 1){
echo '<div class="col-sm-3">';
} else {
echo '<div class="col-sm-4">';
}
echo '</div>';
}
Use foreach to loop your data and do a condition to match if the array key is 1.
foreach ($the_query1->posts as $key => $value) {
if($key == 1){
echo '<div class="col-sm-3">';
} else {
echo '<div class="col-sm-4">';
}
echo '</div>';
}
answered Jan 19 at 16:13
EmeraldEmerald
416418
416418
When I do a var_dump on $key, I get NULL. Also get NULL for $value.
– mdarmanin
Jan 19 at 16:59
Do the var_dump inside the foreach. You should be able to see the value of the key.
– Emerald
Jan 20 at 8:43
I did the var_dump inside the for loop, but I can't find the log anywhere in console. I've also installed WordPress PHP console, and even there, there is no log being made. Why is that?
– mdarmanin
Jan 20 at 11:09
add a comment |
When I do a var_dump on $key, I get NULL. Also get NULL for $value.
– mdarmanin
Jan 19 at 16:59
Do the var_dump inside the foreach. You should be able to see the value of the key.
– Emerald
Jan 20 at 8:43
I did the var_dump inside the for loop, but I can't find the log anywhere in console. I've also installed WordPress PHP console, and even there, there is no log being made. Why is that?
– mdarmanin
Jan 20 at 11:09
When I do a var_dump on $key, I get NULL. Also get NULL for $value.
– mdarmanin
Jan 19 at 16:59
When I do a var_dump on $key, I get NULL. Also get NULL for $value.
– mdarmanin
Jan 19 at 16:59
Do the var_dump inside the foreach. You should be able to see the value of the key.
– Emerald
Jan 20 at 8:43
Do the var_dump inside the foreach. You should be able to see the value of the key.
– Emerald
Jan 20 at 8:43
I did the var_dump inside the for loop, but I can't find the log anywhere in console. I've also installed WordPress PHP console, and even there, there is no log being made. Why is that?
– mdarmanin
Jan 20 at 11:09
I did the var_dump inside the for loop, but I can't find the log anywhere in console. I've also installed WordPress PHP console, and even there, there is no log being made. Why is that?
– mdarmanin
Jan 20 at 11:09
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54268804%2fcheck-if-array-index-is-1-in-php-array%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Are you just spamming your question on SO multiple times or is this a completely different problem? It sounds exactly the same as previous 2 or 3 of your questions
– Dharman
Jan 19 at 15:54
The last question didn't solve my problem, so I rephrased the question. Not my intention to spam.
– mdarmanin
Jan 19 at 15:55
2
What do you mean by the current index is in position 1?
– Nigel Ren
Jan 19 at 15:57
where is the code you try that needs to
check if the current index?– Pete Houston
Jan 19 at 15:57
2
"so I rephrased the question" - You should edit the existing questions to be clear instead of writing new ones.
– Magnus Eriksson
Jan 19 at 16:06