providing one argument for multiple vars in printf()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    providing one argument for multiple vars in printf()

    without babbling too much here's what I'm looking for:

    printf("%s is the same as %s","A Duck")

    to output
    "A Duck is the same as A Duck";

    But of course, if you know how to use it, to get that output you must provide the argument "This" twice, such as:

    printf("%s is the same as %s","A Duck","A Duck");

    This is a cumbersome way to give a value to a variable that is repeated many times in a formatted string. What if it was 50 times?

    Yes, I can use str_replace. but wondering if this is impossible to do. I've tried giving them the same order, like so: "%1s is the same as %1s", but still doesn't work.

    Thanks,






    Dan
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Code:
    printf("%1$s is the same as %1$s","A Duck")
    it's mentioned somewhere in the examples.

    Comment

    Working...