K
K
khodos_dmitry2018-02-27 11:38:10
PHP
khodos_dmitry, 2018-02-27 11:38:10

How to access a specific element by number in phpQuery?

phpQuery finds multiple entries. You can iterate through them with foreach. But how to access a specific record?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
khodos_dmitry, 2018-03-02
@khodos_dmitry

I accessed it like this:
$links = $pq->find('a');
$three = $links->eq(3);

I
ivankomolin, 2018-02-27
@ivankomolin

$links = $pq->find('a');

//Выведет 3ю найденную ссылку
var_dump($links[2]);

N
Nick Sdk, 2018-02-27
@lidacriss

$elements = $doc->find('element');
// 2-й элемент:
$need_element = $elements->get(1);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question