最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Echo multiple tasks if a common function exists

programmeradmin0浏览0评论

How can I echo multiple tasks if a common WordPress function exists.

For example, I want to reduce the following:

<?php if (function_exists ('pluginName')) echo someName (1); ?>
<?php if (function_exists ('pluginName')) echo someName (2); ?>
<?php if (function_exists ('pluginName')) echo someName (3); ?>
<?php if (function_exists ('pluginName')) echo someName (4); ?>

into a single query like this:

<?php if (function_exists ('pluginName')) echo someName (1); someName (2); someName (3); someName (4); ?>

What is the right way to do it?

How can I echo multiple tasks if a common WordPress function exists.

For example, I want to reduce the following:

<?php if (function_exists ('pluginName')) echo someName (1); ?>
<?php if (function_exists ('pluginName')) echo someName (2); ?>
<?php if (function_exists ('pluginName')) echo someName (3); ?>
<?php if (function_exists ('pluginName')) echo someName (4); ?>

into a single query like this:

<?php if (function_exists ('pluginName')) echo someName (1); someName (2); someName (3); someName (4); ?>

What is the right way to do it?

Share Improve this question edited May 12, 2016 at 12:19 fuxia 107k38 gold badges255 silver badges459 bronze badges asked May 11, 2016 at 18:13 AndrewL64AndrewL64 2034 silver badges18 bronze badges 4
  • 1 Brackets may help. See second example - the one with multiple statements. – Howdy_McGee Commented May 11, 2016 at 18:17
  • Something like this? -> <?php if (function_exists ('pluginName')) { echo someName (7); echo someName (8); echo someName (9); } ?> – AndrewL64 Commented May 11, 2016 at 18:21
  • 1 Yup, that'll do it. – Howdy_McGee Commented May 11, 2016 at 18:21
  • Thank you good sir. Do add that as the answer and I'll mark it as correct. – AndrewL64 Commented May 11, 2016 at 18:23
Add a comment  | 

1 Answer 1

Reset to default 0

As @Howdy_McGee mentioned in the comments, you can just wrapped the multiple commands you want to run within curly brackets like this:

<?php if (function_exists ('pluginName')) { echo someName (7); echo someName (8); echo someName (9); } ?>
发布评论

评论列表(0)

  1. 暂无评论