to check the keys and their associated values, check the output from print_r().
Trouble when using 'array_rand' (displaying numbers instead of array items)
Collapse
X
-
I tried this:
And it gives this output:Code:$style_class = array("styles" => "story_style1","story_style2","story_style3","story_style4"); $div_class = print_r($style_class); $storyDisplayList .= '<div class="'. $div_class .'"></div>
Am I suppose to somehow use it to achieve the task?Code:Array ( [styles] => story_style1 [0] => story_style2 [1] => story_style3 [2] => story_style4 )
ThnxComment
-
I am really stuck and confused now...
So I will not use the print_r();
Instead I'll do this
This gives output ofCode:$style_class = array("styles" => "story_style1","story_style2","story_style3","story_style4"); $div_class = array_rand($style_class); $storyDisplayList .= '<div class="'. $div_class .'"><div class="styles"> </div>
So what Am I suppose to do to get final result of
I just don't understand what I need to do now...Code:<div class="story_style1"></div> <div class="story_style3"></div> <div class="story_style2"></div> <div class="story_style4"></div> <div class="story_style3"></div> <div class="story_style1"></div> <div class="story_style4"></div> and so on ...
ThnxComment
-
Yeh, I understood that when I saw the output, but do you have any suggestion of what I should do next? You can see what I have now in my previous post, I'm now stuck with next step, I have no idea what to do to complete it. This feature is one of the main that I need for my website design, so I really need to understand and get it working... So if you have any suggestions or could point where the issue is could you please help me?
Thank YouComment
-
I know how to do it, it’s just that I am not the best teacher. and I deem teaching necessary, as this problem turned out to be a very basic one. i.e. giving you the answer would solve the case, but you wouldn’t have a clue what went wrong in the first place.
maybe we should have an IM session later, as there explanation goes smoother.Comment
-
That would be great, you have been great help, I think that's mee who got things wrong I just got messed up and confused my selves, usually I understand where the problem is when I ask it here, but this is something new in PHP that I don't know yet.
If you have free time it would be great to chat, do you have skype? I don't want others to see my nick name here so if you could e-mail me your contact details …Comment
-
Hi ;D
It took me a while of research, but I think I figured it out )))
It gives me output that I wanted in my source code, now div's have random classes that I want, but for some reason that I don't understand :/ I get this thingCode:$style_class = array("story_style1","story_style2","story_style3","story_style4"); $random_class = array_rand($style_class, 1); var_dump($random_class); $div_class = $style_class[$random_class]; $storyDisplayList .= '<div class="' . $div_class . '"></div>
int(1) int(2) int(0) int(3) int(3) int(2) int(3)
On the top of my page, http://inelmo.com < you can see what I mean there.
UPDATE: I also remembered that I echo out all errors while I'm in the process of creation
e.g
Could this be what is causing the problem? As I am not sure whether that is an error or output.Code:error_reporting(0); ini_set('display_errors', '1');Comment
-
that is the output generated by var_dump() (line #5)It gives me output that I wanted in my source code, now div's have random classes that I want, but for some reason that I don't understand :/ I get this thing
int(1) int(2) int(0) int(3) int(3) int(2) int(3)Comment
-
Ohhhh ;D Finally what a relief, it work's now just As I wanted.
Thank You Very Much For Awesome help and explaining I really appreciate that! Sorry for taking so much time (25 posts) ;D .Comment
-
this would have been the short, unexplained answer, which I had in mind in post #4.
Code:$style_array = array("story_style1", "story_style2", "story_style3", "story_style4"); $storyDisplayList .= '<div class="' . $style_array[array_rand($style_array)] . '"></div>Comment
Comment