Jump to content

[SOLVED] simple PHP syntax


ssuubb

Recommended Posts

hi everyone - my apologies for what may be a simple question, but i just cant get my head around it!

 

below is a script which i am using, and it is working properly when printing to the browser like so:

 

print("".$urls[$day]);

 

but i need to use the $urls[$day] output in the following query_posts command.

 

normal usage of the query_posts commad would be the following:

 

query_posts('p=34')

 

but i am using the script below to specify the argument based on the day of the month. ie. on the 12th day of the month $urls[$day] would output p=34

 

my problem is that i dont know how to specify the $urls[$day] argument:

 

query_posts('.$urls[$day].')

 

the above makes sense to me, but i obviously have no idea!

 

any help would be greeted with real unadulterated gratitude from myself.

 

thanks for reading!

 

<?php
// Data here
$day1='data1';
$day2='data2';
$day3='data3';
$day4='data4';
$day5='data5';
$day6='data6';
$day7='data7';
$day8='data8';
$day9='data9';
$day10='data10';
$day11='data11';
$day12='p=34';
$day13='data13';
$day14='data14';
$day15='data15';
$day16='data16';
$day17='data17';
$day18='data18';
$day19='data19';
$day20='data20';
$day21='data21';
$day22='data22';
$day23='data23';
$day24='data24';
$day25='data25';
$day26='data26';
$day27='data27';
$day28='data28';
$day29='data29';
$day30='data30';
$day31='data31';
//Make the array
$urls=array($day1, $day2, $day3, $day4, $day5, $day6, $day6,
$day7, $day8, $day9, $day10, $day11, $day12, $day13,
$day14, $day15, $day16, $day17, $day18, $day19, $day20,
$day21, $day22, $day23, $day24, $day25, $day26, $day27,
$day28, $day29, $day30, $day31);
//Get day of the month
$day=date("j");
//Print in broswer


query_posts('.$urls[$day]');      
?>

Link to comment
https://forums.phpfreaks.com/topic/169977-solved-simple-php-syntax/
Share on other sites

I'm not sure I understand your question completely. But just by looking at the code I'm guessing you want this:

 

query_posts($urls[$day]);

Anything inbetween single quotes will be parsed as a string. So instead of the value of $urls[$day], it would literally be the string '$urls[$day]', and you had a period in there  :shrug:

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.