Jump to content

Recommended Posts

I have this function:

function echo_exist($pre1,$ee,$post1) {
if ($ee!='') {
	return $pre1;
	return $ee;
	return $post1;
}
else {
	//do nothing
}
}

 

But when I try to echo it

echo_exist("(","$row['payment_type']",")");

 

I get syntax error, unexpected T_ENCAPSED_AND_WHITESPACE

If $row['payment_type'] exists, I want it to be displayed in parentheses like:  (AUTO)

 

I suspect it has to do with my ' characters for the associative array, but I am new with functions so perhaps it is the multiple arguments that are wrong?

1. You can't have multiple return statements like the way you have them.  Return returns that value from the function and then EXITS the function.  Everything else below the initial returns won't be executed.

 

2. I'm not sure what you're attempting to do when you try to invoke the function.  What's with all the double quotes and extra parenthesese?  Where's your echo statement?

 

Have you read about functions in the online manual (functions)?

1. passing parenthesis into a function is pointless, as the display can be handled with PHP after the function has returned the necessary data.

 

2. If you simply want to check for a variable being empty, use the empty function that PHP provides.

 

Well, I am constantly typing

if ($row['name'])!=''){ echo "the name is ". $row['name'];

so I figured I would make a function to save keystrokes. so all I would have to do would type

echo_if_exist($row['name'])

.

  But also, sometimes I want to precede the variable with "the name is" and sometimes I want to simply surround it in a parenthesis.

 

I guess my experiment on trying to use a function failed.

 

Oh I just saw that new post - I will look into empty()...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.