How to create loop templates in php


Last Update : 2023-09-22 UTC 11:45:25 AM

Answers of > How to create loop templates in php

An interesting preprocessor for PHP was w3coded developer c PiHiPi which tried to add useful features to the w3coded developer c language like JSON like array syntax, rather w3coded developer c than needing to write array() every time. w3coded developer c Unfortunately, the author has pulled it., w3coded developer c 3 w3coded developer c w3coded developer c @rjmunro, macros are cuddly. w3coded developer c Embrace them. (I prefer simple text-replace w3coded developer c ones.) PHP is a very neat language so there's w3coded developer c less need for them than in other languages, but w3coded developer c they're nifty for shortening and simplifying w3coded developer c largish blocks of code, making it more readable. w3coded developer c If Objective-C didn't have macros I'd become w3coded developer c homicidal. w3coded developer c – Henrik Erlandsson w3coded developer c May 9 '12 at 11:29 w3coded developer c , w3coded developer c w3coded developer c While certainly a valid answer, I maybe w3coded developer c edited out too much of the original question, as w3coded developer c it involves opening a new scope directly after w3coded developer c the macro. Brb, editing. w3coded developer c – Xeo w3coded developer c May 28 '11 at 17:22 w3coded developer c ,Disclaimer: Well, this is not exactly w3coded developer c preprocessor macro, but due to "dynamic" nature w3coded developer c of PHP, preprocessors are not needed/used. w3coded developer c Instead however, you are able to wrap functions w3coded developer c in other functions, like in the example w3coded developer c below.

Yes, you can do this by creating your own function that is being passed also a callback. Here is the example:

// FO function
function fo($b, $c, $callback) {
    for ($a = $b; $a < $c; ++$a) {

// example of usage
fo(2,10, function($a){
    echo '['.$a.']';

The above code works in PHP 5.3 and outputs the following:


How about something like:

function my_macro($a, $b, $c) {
  $args = func_get_args();

  return call_user_func_array("something_horrifically_long_involving_{$a}_{$b}_and_{$c}", $args);

CCPP seems to be closest thing available:

#define macroFunction(op1,op2,op3) ((int)op1/((int)op2+(int)op3))
#define hash_hash # ## #
#define showCExamples 1

#if showCExamples
#define MYCASE(item,id) \
case id: \
  item##_##id = id;\

switch(x) {

Current topics : How to create loop templates in php

Newly Added Questions

Similar Questions

Questions :

How To Group Array Key Value

Last Update : 2023-09-22 UTC 14:08:37 PM

Questions :

PhpStorm Warning For React Attributes In Jsx File With SCSS File

Last Update : 2023-09-22 UTC 14:08:23 PM

Questions :

Why Is The File Not Showing Up In Request.files And In Request.forms Instead?

Last Update : 2023-09-22 UTC 14:08:14 PM

Questions :

Proxying Assets From React App Directory In Slim Framework?

Last Update : 2023-09-22 UTC 14:07:54 PM

Questions :

Laravel 5.4 Can't Run “php Artisan Preset React” Comand

Last Update : 2023-09-22 UTC 14:07:34 PM

Questions :

How To Update Session Values Without Signing Out?

Last Update : 2023-09-22 UTC 14:07:25 PM

Questions :

Array Is Not Visible

Last Update : 2023-09-22 UTC 14:07:09 PM

Questions :

React Routing For Login Using Symfony

Last Update : 2023-09-22 UTC 14:07:02 PM

Questions :

Sanctum With React SPA Returning 419 Page Expired

Last Update : 2023-09-22 UTC 14:06:46 PM

Questions :

How Do I Import An Input String Into Another Page

Last Update : 2023-09-22 UTC 14:06:29 PM

© 2023 W3CODED - All Rights Reserved.