Status
Not open for further replies.

viruz99

Active Member
1,547
2010
96
0
Hey Guys , need some help with the code below :

$var1 = $images[0]; // Source Image
$var2 = $screens; // Screenshots
$var3 = "http://url/defaultimage.jpg";

Need a simple function to check whether $var1 = ( blank , Null , array) in which case it uses $var2 & if $var2 = ( blank , Null , array) , then it uses $var3 .

I got part of it working but still needs some work and i'm not very good with php :



$image = $var1;

if (($var1 == NULL) || ($var1 == "") || ($var1 == "Array") || (is_array($var1)))
{
$image = $var2;
}
if (($var2 == NULL) || ($var2 == "") || ($var2 == "Array") || (is_array($var2)))
{
$image = $var3;
}





 
6 comments
any way to do it for 3 parts ?

In the above case , its only for the $images[0] & the $screens

But i got 1 more as last resort for a default pic

I need it to use the $image[0] first if available , then the screens , then the default if the 2 above is not available.




 
Last edited:
just noticed i added only a else check other then else if so this one should work:

PHP:
$defaultimage = "http://url/defaultimage.jpg";
$image = "";

if (empty($images[0])) {
    if (empty($screens)) 
        $image = $defaultimage;
    else
        $image = $screens;
} else {
    $image = $images[0];  
}
 
Last edited:
In a few cases the $screens may not be present so it gives this error :


Notice: Undefined variable: screens in C:\xampp\htdocs\qtest.php on line 6






 
The edited reply should work then.

Check if $images[0] is empty, If It is then it checks the same for $screens
If $screen is also empty then sets the default variable else $image = $screen
 
Status
Not open for further replies.
Back
Top