How to call if condition if only one array is empty if both empty then call else condition?
I am using CodeIgniter. I am getting the response from model and display on the controller.
Model
//some code here
return array('secondary_data'=> $result,'primary_data' =>$result2);// sending to controller
// some code here
Controller
$result=$this->Search_model->get_search_name($cust_name);//calling model
$data['secondary_data'] = $result['secondary_data'];
$data['primary_data'] = $result['primary_data'];
print_r($data['secondary_data']);
print_r($data['primary_data']);
output
Array
(
[0] => stdClass Object
(
[member_id] =>
[customer_id] =>
[first_name] => qwer
[last_name] => poiu
[email] =>
[member_type] => 2
)
)
Array
(
[0] => stdClass Object
(
[member_id] => 1
[customer_id] => 0011
[first_name] => asdasd
[last_name] => asdasda
[email] => bappyang68@gmail.com
[member_type] => 1
)
)
but sometimes I am getting empty array of print_r($data['primary_data'])
because of no data. Yes, it's possible.;
but in below if condition I am checking the data count count($data) > 0
and if found empty then calling the else part.
I don't want to call else part if only one array is emply. if both array is empty then it should call else part
if (count($data) > 0)
{
$data['title'] = "Search";
$data['heading'] = "Search";
$data['content'] = $this->load->view('search',$data,true);
$this->load->view('dashboard/dashboard',$data);
}
else{
echo "NO data available";
}
Any idea how to do this? Thanks
php codeigniter-3
add a comment |
I am using CodeIgniter. I am getting the response from model and display on the controller.
Model
//some code here
return array('secondary_data'=> $result,'primary_data' =>$result2);// sending to controller
// some code here
Controller
$result=$this->Search_model->get_search_name($cust_name);//calling model
$data['secondary_data'] = $result['secondary_data'];
$data['primary_data'] = $result['primary_data'];
print_r($data['secondary_data']);
print_r($data['primary_data']);
output
Array
(
[0] => stdClass Object
(
[member_id] =>
[customer_id] =>
[first_name] => qwer
[last_name] => poiu
[email] =>
[member_type] => 2
)
)
Array
(
[0] => stdClass Object
(
[member_id] => 1
[customer_id] => 0011
[first_name] => asdasd
[last_name] => asdasda
[email] => bappyang68@gmail.com
[member_type] => 1
)
)
but sometimes I am getting empty array of print_r($data['primary_data'])
because of no data. Yes, it's possible.;
but in below if condition I am checking the data count count($data) > 0
and if found empty then calling the else part.
I don't want to call else part if only one array is emply. if both array is empty then it should call else part
if (count($data) > 0)
{
$data['title'] = "Search";
$data['heading'] = "Search";
$data['content'] = $this->load->view('search',$data,true);
$this->load->view('dashboard/dashboard',$data);
}
else{
echo "NO data available";
}
Any idea how to do this? Thanks
php codeigniter-3
if(count($data) && (!empty($data['secondary_data']) || !empty($data['primary_data']))){...}else{...}
– suresh bambhaniya
Nov 16 '18 at 6:15
writecondition for both array
or Useloop
and check
– Bhargav Chudasama
Nov 16 '18 at 6:16
add a comment |
I am using CodeIgniter. I am getting the response from model and display on the controller.
Model
//some code here
return array('secondary_data'=> $result,'primary_data' =>$result2);// sending to controller
// some code here
Controller
$result=$this->Search_model->get_search_name($cust_name);//calling model
$data['secondary_data'] = $result['secondary_data'];
$data['primary_data'] = $result['primary_data'];
print_r($data['secondary_data']);
print_r($data['primary_data']);
output
Array
(
[0] => stdClass Object
(
[member_id] =>
[customer_id] =>
[first_name] => qwer
[last_name] => poiu
[email] =>
[member_type] => 2
)
)
Array
(
[0] => stdClass Object
(
[member_id] => 1
[customer_id] => 0011
[first_name] => asdasd
[last_name] => asdasda
[email] => bappyang68@gmail.com
[member_type] => 1
)
)
but sometimes I am getting empty array of print_r($data['primary_data'])
because of no data. Yes, it's possible.;
but in below if condition I am checking the data count count($data) > 0
and if found empty then calling the else part.
I don't want to call else part if only one array is emply. if both array is empty then it should call else part
if (count($data) > 0)
{
$data['title'] = "Search";
$data['heading'] = "Search";
$data['content'] = $this->load->view('search',$data,true);
$this->load->view('dashboard/dashboard',$data);
}
else{
echo "NO data available";
}
Any idea how to do this? Thanks
php codeigniter-3
I am using CodeIgniter. I am getting the response from model and display on the controller.
Model
//some code here
return array('secondary_data'=> $result,'primary_data' =>$result2);// sending to controller
// some code here
Controller
$result=$this->Search_model->get_search_name($cust_name);//calling model
$data['secondary_data'] = $result['secondary_data'];
$data['primary_data'] = $result['primary_data'];
print_r($data['secondary_data']);
print_r($data['primary_data']);
output
Array
(
[0] => stdClass Object
(
[member_id] =>
[customer_id] =>
[first_name] => qwer
[last_name] => poiu
[email] =>
[member_type] => 2
)
)
Array
(
[0] => stdClass Object
(
[member_id] => 1
[customer_id] => 0011
[first_name] => asdasd
[last_name] => asdasda
[email] => bappyang68@gmail.com
[member_type] => 1
)
)
but sometimes I am getting empty array of print_r($data['primary_data'])
because of no data. Yes, it's possible.;
but in below if condition I am checking the data count count($data) > 0
and if found empty then calling the else part.
I don't want to call else part if only one array is emply. if both array is empty then it should call else part
if (count($data) > 0)
{
$data['title'] = "Search";
$data['heading'] = "Search";
$data['content'] = $this->load->view('search',$data,true);
$this->load->view('dashboard/dashboard',$data);
}
else{
echo "NO data available";
}
Any idea how to do this? Thanks
php codeigniter-3
php codeigniter-3
asked Nov 16 '18 at 6:11
user9437856user9437856
481314
481314
if(count($data) && (!empty($data['secondary_data']) || !empty($data['primary_data']))){...}else{...}
– suresh bambhaniya
Nov 16 '18 at 6:15
writecondition for both array
or Useloop
and check
– Bhargav Chudasama
Nov 16 '18 at 6:16
add a comment |
if(count($data) && (!empty($data['secondary_data']) || !empty($data['primary_data']))){...}else{...}
– suresh bambhaniya
Nov 16 '18 at 6:15
writecondition for both array
or Useloop
and check
– Bhargav Chudasama
Nov 16 '18 at 6:16
if(count($data) && (!empty($data['secondary_data']) || !empty($data['primary_data']))){...}else{...}
– suresh bambhaniya
Nov 16 '18 at 6:15
if(count($data) && (!empty($data['secondary_data']) || !empty($data['primary_data']))){...}else{...}
– suresh bambhaniya
Nov 16 '18 at 6:15
write
condition for both array
or Use loop
and check– Bhargav Chudasama
Nov 16 '18 at 6:16
write
condition for both array
or Use loop
and check– Bhargav Chudasama
Nov 16 '18 at 6:16
add a comment |
4 Answers
4
active
oldest
votes
Check your both array separately in or condition
if (count($data['primary_data']) > 0 || count($data['secondary_data']) > 0)
{
$data['title'] = "Search";
$data['heading'] = "Search";
$data['content'] = $this->load->view('search',$data,true);
$this->load->view('dashboard/dashboard',$data);
}else{
echo "NO data available";
}
add a comment |
Try this condition with OR operator
if(!empty($data['primary_data']) || !empty($data['secondary_data'])){
//One or both array have values
}else{
//Both have no values
}
Your code is also working for me. upvote from my side
– user9437856
Nov 16 '18 at 7:51
1
This is short and simple solution.
– Smartpal
Nov 16 '18 at 7:52
add a comment |
You can use separate condition for both array, If one of them is not empty then apply If condition otherwise else.
if ( !empty($data['secondary_data']) || !empty($data['primary_data']) ) {
$data['title'] = "Search";
$data['heading'] = "Search";
$data['content'] = $this->load->view('search',$data,true);
$this->load->view('dashboard/dashboard',$data);
} else {
echo "NO data available";
}
add a comment |
start checking from $data then sub array
if(count($data) && (isset($data['secondary_data']) && !empty($data['secondary_data'])) || (isset($data['primary_data']) && !empty($data['primary_data']))){
....
}else{
...
}
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%2f53332375%2fhow-to-call-if-condition-if-only-one-array-is-empty-if-both-empty-then-call-else%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Check your both array separately in or condition
if (count($data['primary_data']) > 0 || count($data['secondary_data']) > 0)
{
$data['title'] = "Search";
$data['heading'] = "Search";
$data['content'] = $this->load->view('search',$data,true);
$this->load->view('dashboard/dashboard',$data);
}else{
echo "NO data available";
}
add a comment |
Check your both array separately in or condition
if (count($data['primary_data']) > 0 || count($data['secondary_data']) > 0)
{
$data['title'] = "Search";
$data['heading'] = "Search";
$data['content'] = $this->load->view('search',$data,true);
$this->load->view('dashboard/dashboard',$data);
}else{
echo "NO data available";
}
add a comment |
Check your both array separately in or condition
if (count($data['primary_data']) > 0 || count($data['secondary_data']) > 0)
{
$data['title'] = "Search";
$data['heading'] = "Search";
$data['content'] = $this->load->view('search',$data,true);
$this->load->view('dashboard/dashboard',$data);
}else{
echo "NO data available";
}
Check your both array separately in or condition
if (count($data['primary_data']) > 0 || count($data['secondary_data']) > 0)
{
$data['title'] = "Search";
$data['heading'] = "Search";
$data['content'] = $this->load->view('search',$data,true);
$this->load->view('dashboard/dashboard',$data);
}else{
echo "NO data available";
}
edited Nov 16 '18 at 6:20
answered Nov 16 '18 at 6:15
SachinSachin
610412
610412
add a comment |
add a comment |
Try this condition with OR operator
if(!empty($data['primary_data']) || !empty($data['secondary_data'])){
//One or both array have values
}else{
//Both have no values
}
Your code is also working for me. upvote from my side
– user9437856
Nov 16 '18 at 7:51
1
This is short and simple solution.
– Smartpal
Nov 16 '18 at 7:52
add a comment |
Try this condition with OR operator
if(!empty($data['primary_data']) || !empty($data['secondary_data'])){
//One or both array have values
}else{
//Both have no values
}
Your code is also working for me. upvote from my side
– user9437856
Nov 16 '18 at 7:51
1
This is short and simple solution.
– Smartpal
Nov 16 '18 at 7:52
add a comment |
Try this condition with OR operator
if(!empty($data['primary_data']) || !empty($data['secondary_data'])){
//One or both array have values
}else{
//Both have no values
}
Try this condition with OR operator
if(!empty($data['primary_data']) || !empty($data['secondary_data'])){
//One or both array have values
}else{
//Both have no values
}
answered Nov 16 '18 at 6:18
SmartpalSmartpal
982517
982517
Your code is also working for me. upvote from my side
– user9437856
Nov 16 '18 at 7:51
1
This is short and simple solution.
– Smartpal
Nov 16 '18 at 7:52
add a comment |
Your code is also working for me. upvote from my side
– user9437856
Nov 16 '18 at 7:51
1
This is short and simple solution.
– Smartpal
Nov 16 '18 at 7:52
Your code is also working for me. upvote from my side
– user9437856
Nov 16 '18 at 7:51
Your code is also working for me. upvote from my side
– user9437856
Nov 16 '18 at 7:51
1
1
This is short and simple solution.
– Smartpal
Nov 16 '18 at 7:52
This is short and simple solution.
– Smartpal
Nov 16 '18 at 7:52
add a comment |
You can use separate condition for both array, If one of them is not empty then apply If condition otherwise else.
if ( !empty($data['secondary_data']) || !empty($data['primary_data']) ) {
$data['title'] = "Search";
$data['heading'] = "Search";
$data['content'] = $this->load->view('search',$data,true);
$this->load->view('dashboard/dashboard',$data);
} else {
echo "NO data available";
}
add a comment |
You can use separate condition for both array, If one of them is not empty then apply If condition otherwise else.
if ( !empty($data['secondary_data']) || !empty($data['primary_data']) ) {
$data['title'] = "Search";
$data['heading'] = "Search";
$data['content'] = $this->load->view('search',$data,true);
$this->load->view('dashboard/dashboard',$data);
} else {
echo "NO data available";
}
add a comment |
You can use separate condition for both array, If one of them is not empty then apply If condition otherwise else.
if ( !empty($data['secondary_data']) || !empty($data['primary_data']) ) {
$data['title'] = "Search";
$data['heading'] = "Search";
$data['content'] = $this->load->view('search',$data,true);
$this->load->view('dashboard/dashboard',$data);
} else {
echo "NO data available";
}
You can use separate condition for both array, If one of them is not empty then apply If condition otherwise else.
if ( !empty($data['secondary_data']) || !empty($data['primary_data']) ) {
$data['title'] = "Search";
$data['heading'] = "Search";
$data['content'] = $this->load->view('search',$data,true);
$this->load->view('dashboard/dashboard',$data);
} else {
echo "NO data available";
}
answered Nov 16 '18 at 6:18
Gajanan KolpukeGajanan Kolpuke
9910
9910
add a comment |
add a comment |
start checking from $data then sub array
if(count($data) && (isset($data['secondary_data']) && !empty($data['secondary_data'])) || (isset($data['primary_data']) && !empty($data['primary_data']))){
....
}else{
...
}
add a comment |
start checking from $data then sub array
if(count($data) && (isset($data['secondary_data']) && !empty($data['secondary_data'])) || (isset($data['primary_data']) && !empty($data['primary_data']))){
....
}else{
...
}
add a comment |
start checking from $data then sub array
if(count($data) && (isset($data['secondary_data']) && !empty($data['secondary_data'])) || (isset($data['primary_data']) && !empty($data['primary_data']))){
....
}else{
...
}
start checking from $data then sub array
if(count($data) && (isset($data['secondary_data']) && !empty($data['secondary_data'])) || (isset($data['primary_data']) && !empty($data['primary_data']))){
....
}else{
...
}
answered Nov 16 '18 at 6:25
suresh bambhaniyasuresh bambhaniya
945415
945415
add a comment |
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%2f53332375%2fhow-to-call-if-condition-if-only-one-array-is-empty-if-both-empty-then-call-else%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
if(count($data) && (!empty($data['secondary_data']) || !empty($data['primary_data']))){...}else{...}
– suresh bambhaniya
Nov 16 '18 at 6:15
write
condition for both array
or Useloop
and check– Bhargav Chudasama
Nov 16 '18 at 6:16