function createDoc() { global $titles, $authors, $categories, $tags; $title = getRandomArrayItem($titles); $author = getRandomArrayItem($authors); $category = getRandomArrayItem($categories); $articleTags = array(); $numOfTags = rand(1, 5); for ($j = 0; $j < $numOfTags; $j++) { $tag = getRandomArrayItem($tags); if (!in_array($tag, $articleTags)) { array_push($articleTags, $tag); } } $publishedAt = new MongoDate(getRandomTimestamp()); $rating = mt_rand(1, 10); return array('title' => $title, 'author' => $author, 'category' => $category, 'tags' => $articleTags, 'published_at' => $publishedAt, 'rating' => $rating); }
function createDoc() { global $titulos, $autores, $categorias, $tags; $titulo = getRandomArrayItem($titulos); $autor = getRandomArrayItem($autores); $categoria = getRandomArrayItem($categorias); $articleTags = array(); $numOfTags = rand(1, 5); for ($j = 0; $j < $numOfTags; $j++) { $tag = getRandomArrayItem($tags); if (!in_array($tag, $articleTags)) { array_push($articleTags, $tag); } } $publishedAt = new MongoDate(getRandomTimestamp()); $rating = mt_rand(1, 10); return array('titulo' => $titulo, 'autor' => $autor, 'categoria' => $categoria, 'tags' => $articleTags, 'publicado_el' => $publishedAt, 'rating' => $rating); }