如何从PHP仓库提取特定书籍数据并筛选英文书籍?
Hey there! Sounds like you hit a snag with the get function—don’t worry, filtering and extracting data from a book repo is totally manageable with simpler, more targeted approaches. Let’s break this down step by step:
1. First: Filter for English-Only Books
The core here is using filtering logic to narrow down your list to just English books. This works whether your repo is an array of objects, a database table, or a framework-specific collection.
Example 1: Python (List of Dictionaries)
If your books are stored in a list of dictionaries:
# Sample book repository book_repo = [ {"title": "The Great Gatsby", "language": "English", "author": "F. Scott Fitzgerald"}, {"title": "1984", "language": "English", "author": "George Orwell"}, {"title": "El amor en los tiempos del cólera", "language": "Spanish", "author": "Gabriel García Márquez"} ] # Filter English books (case-insensitive check to avoid misses) english_books = [book for book in book_repo if book["language"].lower() == "english"]
Example 2: JavaScript (Array of Objects)
For JavaScript-based repos:
// Sample book repository const bookRepo = [ {title: "The Great Gatsby", language: "English", author: "F. Scott Fitzgerald"}, {title: "1984", language: "English", author: "George Orwell"}, {title: "El amor en los tiempos del cólera", language: "Spanish", author: "Gabriel García Márquez"} ]; // Filter English books const englishBooks = bookRepo.filter(book => book.language.toLowerCase() === "english");
Example 3: SQL Database
If your books live in a SQL database, handle filtering directly in your query:
SELECT * FROM books WHERE language = 'English';
2. Extract Specific Data from the Filtered List
Once you have your English-only subset, use a mapping function to pull only the fields you need (like title, author, ISBN, etc.).
Python Example
# Extract just title and author from English books target_data = [{"title": book["title"], "author": book["author"]} for book in english_books]
JavaScript Example
// Extract just title and author from English books const targetData = englishBooks.map(book => ({title: book.title, author: book.author}));
Why get Might Have Failed
The get function (like Python’s dict.get() or Lodash’s _.get()) is built to safely retrieve a single value from an object, not to filter or transform entire collections. It’s perfect for grabbing one field from a single book, but not for bulk operations like what you’re tackling.
This filter-then-map approach is the most straightforward solution—it’s readable, maintainable, and works across nearly all programming languages and data storage systems.
内容的提问来源于stack exchange,提问作者Vic Alfieri

