hello....

it could be interesting.......my frnd asked a question to me...on if else condition.
for suppose...

<?php
if(Condition)
{
echo "hello";
}
else
{
echo "world";
}

it is the question. she asked me how to write condition for print hello world.

Recommended Answers

All 10 Replies

Your setup will either echo "hello" or echo "world", but the way it's set up it will never output "hello world." So what was the question?

What ever you are asking may happen using switch..case statement without using break

switch ($variable)
{
case '1':
      print "hello";
      //break;
case '2':
      print "world";
}
Member Avatar for rajarajan2017
switch ($variable)
{
case '1':
      print "hello";
case '2':
      print "world";
case default:
      print "hello world";
}

if you give 1: prints hello world 2: world apart from these always print "hello world"

if you give 1: prints hello world 2: world apart from these always print "hello world"

rajarajan as you have not used break statement, your code will give following output
on 1) helloworldhello world
on 2) worldhello world
else) hello world

Member Avatar for rajarajan2017

Oh! Sorry Mistaken. Thanks for your spot.

I cannot understand your question Muralikalpana

I cannot understand your question Muralikalpana

if condition and else condition is there....i want to display
hello world.

<?
if(Condition)
{
echo "hello";
}
else
{
echo "world";
}
?>

then my frnd asked to me what the condition should write in if condition to display "hello world".

Member Avatar for rajarajan2017

Really confused. What is your expectation? if you want "hello world" make it directly for the condition you want. But here what is your condition?

mean the code below?

if(condtion1 && condtion2){
    echo 'Hello Murali!';
}

if condition and else condition is there....i want to display
hello world.

<?
if(Condition)
{
echo "hello";
}
else
{
echo "world";
}
?>

then my frnd asked to me what the condition should write in if condition to display "hello world".

With that code its not possible. Only one of the echo will execute because if(condition)
has only 2 answers, true or false. If its true then echo "hello" else "world". As
suggested my previous post, you might try compound boolean expression.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.